From 393c668c38a152c891cd09fd121edc4c258f6335 Mon Sep 17 00:00:00 2001 From: Gui Meira Date: Wed, 30 May 2018 14:11:59 -0300 Subject: [PATCH 1/4] Update README with proper status code handling --- README.md | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6b4cfc75b..44ba5ab7c 100644 --- a/README.md +++ b/README.md @@ -192,16 +192,20 @@ RNFetchBlob.fetch('GET', 'http://www.example.com/images/img1.png', { Authorization : 'Bearer access-token...', // more headers .. }) - // when response status code is 200 .then((res) => { - // the conversion is done in native code - let base64Str = res.base64() - // the following conversions are done in js, it's SYNC - let text = res.text() - let json = res.json() - + let status = res.info().status; + + if(status == 200) { + // the conversion is done in native code + let base64Str = res.base64() + // the following conversions are done in js, it's SYNC + let text = res.text() + let json = res.json() + } else { + // handle other status codes + } }) - // Status code is not 200 + // Something went wrong: .catch((errorMessage, statusCode) => { // error handling }) From 4c4c5eab7dfec84d748e814e19fe69e2f468efa3 Mon Sep 17 00:00:00 2001 From: Nicolas Van Eenaeme Date: Mon, 4 Jun 2018 13:44:24 +0200 Subject: [PATCH 2/4] sometimes getExternalFilesDir returns null, and the app crashes in this case --- android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java b/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java index 7a7910546..7e29fcce2 100644 --- a/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java +++ b/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java @@ -213,7 +213,11 @@ static public Map getSystemfolders(ReactApplicationContext ctx) state = Environment.getExternalStorageState(); if (state.equals(Environment.MEDIA_MOUNTED)) { res.put("SDCardDir", Environment.getExternalStorageDirectory().getAbsolutePath()); - res.put("SDCardApplicationDir", ctx.getExternalFilesDir(null).getParentFile().getAbsolutePath()); + + File externalDirectory = ctx.getExternalFilesDir(null); + if (externalDirectory != null) { + res.put("SDCardApplicationDir", externalDirectory.getParentFile().getAbsolutePath()); + } } res.put("MainBundleDir", ctx.getApplicationInfo().dataDir); return res; From 3edacb8421f9668d2aa61b55feeb2d1d4454af69 Mon Sep 17 00:00:00 2001 From: Miles Matthias Date: Mon, 11 Jun 2018 14:39:39 -0600 Subject: [PATCH 3/4] Add manual linking instructions There are a million issues around people having issues with automatically linking and having a link to manual instructions would address a lot of these up front. This also follows the instructions pattern of most react native modules. --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 44ba5ab7c..70c6a4818 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,11 @@ After `0.10.3` you can install this package directly from Github # replace with any one of the branches npm install --save github:wkh237/react-native-fetch-blob-package# ``` + +**Manually Link Native Modules** + +If automatically linking doesn't work for you, see instructions on [manually linking](https://github.com/joltup/react-native-fetch-blob/wiki/Manually-Link-Package#index). + **Automatically Link Native Modules** For 0.29.2+ projects, simply link native packages via the following command (note: rnpm has been merged into react-native) From c06d6a00f9ee159a6831dbea05311de9f786edd3 Mon Sep 17 00:00:00 2001 From: Tim-Burbank <445333885@qq.com> Date: Fri, 15 Jun 2018 13:46:14 +0800 Subject: [PATCH 4/4] Update RNFetchBlobReqBuilder.m --- ios/RNFetchBlobReqBuilder.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/RNFetchBlobReqBuilder.m b/ios/RNFetchBlobReqBuilder.m index 15465a1ae..7666489fd 100644 --- a/ios/RNFetchBlobReqBuilder.m +++ b/ios/RNFetchBlobReqBuilder.m @@ -69,7 +69,7 @@ +(void) buildMultipartRequest:(NSDictionary *)options [mheaders setValue:[NSString stringWithFormat:@"%lu",[postData length]] forKey:@"Content-Length"]; [mheaders setValue:@"100-continue" forKey:@"Expect"]; // appaned boundary to content-type - [mheaders setValue:[NSString stringWithFormat:@"multipart/form-data; charset=utf-8; boundary=%@", boundary] forKey:@"content-type"]; + [mheaders setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary] forKey:@"content-type"]; [request setHTTPMethod: method]; [request setAllHTTPHeaderFields:mheaders]; onComplete(request, [formData length]);