From 8121dbf66db16999653a590b1ee41c48add6dba9 Mon Sep 17 00:00:00 2001 From: Ben Hsieh Date: Mon, 27 Mar 2017 22:28:13 +0800 Subject: [PATCH 01/20] Apply possible fix to fs.readFile and fs.readStream for #287 --- .../java/com/RNFetchBlob/RNFetchBlobFS.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java b/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java index b7237a461..7457dba19 100644 --- a/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java +++ b/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java @@ -138,11 +138,13 @@ static public void writeFile(String path, ReadableArray data, final boolean appe * @param promise */ static public void readFile(String path, String encoding, final Promise promise ) { - path = normalizePath(path); + String resolved = normalizePath(path); + if(resolved != null) + path = resolved; try { byte[] bytes; - if(path.startsWith(RNFetchBlobConst.FILE_PREFIX_BUNDLE_ASSET)) { + if(resolved != null && resolved.startsWith(RNFetchBlobConst.FILE_PREFIX_BUNDLE_ASSET)) { String assetName = path.replace(RNFetchBlobConst.FILE_PREFIX_BUNDLE_ASSET, ""); long length = RNFetchBlob.RCTContext.getAssets().openFd(assetName).getLength(); bytes = new byte[(int) length]; @@ -150,6 +152,14 @@ static public void readFile(String path, String encoding, final Promise promise in.read(bytes, 0, (int) length); in.close(); } + // issue 287 + else if(resolved == null) { + InputStream in = RNFetchBlob.RCTContext.getContentResolver().openInputStream(Uri.parse(path)); + int length = (int) in.available(); + bytes = new byte[length]; + in.read(bytes); + in.close(); + } else { File f = new File(path); int length = (int) f.length(); @@ -225,7 +235,9 @@ static public String getTmpPath(ReactApplicationContext ctx, String taskId) { * @param bufferSize Buffer size of read stream, default to 4096 (4095 when encode is `base64`) */ public void readStream(String path, String encoding, int bufferSize, int tick, final String streamId) { - path = normalizePath(path); + String resolved = normalizePath(path); + if(resolved != null) + path = resolved; try { int chunkSize = encoding.equalsIgnoreCase("base64") ? 4095 : 4096; @@ -233,9 +245,13 @@ public void readStream(String path, String encoding, int bufferSize, int tick, f chunkSize = bufferSize; InputStream fs; - if(path.startsWith(RNFetchBlobConst.FILE_PREFIX_BUNDLE_ASSET)) { + if(resolved != null && path.startsWith(RNFetchBlobConst.FILE_PREFIX_BUNDLE_ASSET)) { fs = RNFetchBlob.RCTContext.getAssets().open(path.replace(RNFetchBlobConst.FILE_PREFIX_BUNDLE_ASSET, "")); } + // fix issue 287 + else if(resolved == null) { + fs = RNFetchBlob.RCTContext.getContentResolver().openInputStream(Uri.parse(path)); + } else { fs = new FileInputStream(new File(path)); } From 40fefd4b2e29bdb13c3cbf1e64e0ced2dac33da7 Mon Sep 17 00:00:00 2001 From: Ben Hsieh Date: Sun, 16 Apr 2017 16:34:11 +0800 Subject: [PATCH 02/20] Add Android fs.readFile app provider URI support #287 --- .../java/com/RNFetchBlob/Utils/PathResolver.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/RNFetchBlob/Utils/PathResolver.java b/android/src/main/java/com/RNFetchBlob/Utils/PathResolver.java index e5742b81e..0327c8e26 100644 --- a/android/src/main/java/com/RNFetchBlob/Utils/PathResolver.java +++ b/android/src/main/java/com/RNFetchBlob/Utils/PathResolver.java @@ -59,6 +59,14 @@ else if (isMediaDocument(uri)) { return getDataColumn(context, contentUri, selection, selectionArgs); } + else if ("content".equalsIgnoreCase(uri.getScheme())) { + + // Return the remote address + if (isGooglePhotosUri(uri)) + return uri.getLastPathSegment(); + + return getDataColumn(context, uri, null, null); + } } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { @@ -103,7 +111,12 @@ public static String getDataColumn(Context context, Uri uri, String selection, final int index = cursor.getColumnIndexOrThrow(column); return cursor.getString(index); } - } finally { + } + catch (Exception ex) { + ex.printStackTrace(); + return null; + } + finally { if (cursor != null) cursor.close(); } From 08f8403dc43ad34320ee3038fa877a92b2b735c3 Mon Sep 17 00:00:00 2001 From: Ben Hsieh Date: Mon, 3 Jul 2017 08:48:44 +0800 Subject: [PATCH 03/20] Fixed a bug which causes XMLHttpRequest getting incorrect header when sending multiple requests in the same time --- polyfill/XMLHttpRequest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polyfill/XMLHttpRequest.js b/polyfill/XMLHttpRequest.js index 89171921f..42c987704 100644 --- a/polyfill/XMLHttpRequest.js +++ b/polyfill/XMLHttpRequest.js @@ -277,7 +277,7 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{ _headerReceived = (e) => { log.debug('header received ', this._task.taskId, e) this.responseURL = this._url - if(e.state === "2") { + if(e.state === "2" && e.taskId === this._task.taskId) { this._responseHeaders = e.headers this._statusText = e.status this._status = Math.floor(e.status) From 8a75a9be2a613f6ce78dd6cd0e849437a9a8c41c Mon Sep 17 00:00:00 2001 From: Jon San Miguel Date: Mon, 3 Jul 2017 19:40:08 -0400 Subject: [PATCH 04/20] Set mime if set in addAndroidDownloads (#421) --- android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java b/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java index db213c1e8..56fec29b5 100644 --- a/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java +++ b/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java @@ -148,6 +148,9 @@ public void run() { if(options.addAndroidDownloads.hasKey("path")) { req.setDestinationUri(Uri.parse("file://" + options.addAndroidDownloads.getString("path"))); } + if(options.addAndroidDownloads.hasKey("mime")) { + req.setMimeType(options.addAndroidDownloads.getString("mime")); + } // set headers ReadableMapKeySetIterator it = headers.keySetIterator(); while (it.hasNextKey()) { From ed2732a47ef5b4e7748b4c7632771d6f30a12c88 Mon Sep 17 00:00:00 2001 From: Ben Hsieh Date: Wed, 5 Jul 2017 14:14:16 +0800 Subject: [PATCH 05/20] Fix Download Manager bug when the file is not a multimedia #391 --- .../java/com/RNFetchBlob/RNFetchBlobReq.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java b/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java index db213c1e8..31377650a 100644 --- a/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java +++ b/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java @@ -150,6 +150,14 @@ public void run() { } // set headers ReadableMapKeySetIterator it = headers.keySetIterator(); + // #391 Add MIME type to the request + if(options.addAndroidDownloads.hasKey("mime")) { + req.setMimeType(options.addAndroidDownloads.getString("mime")); + } + + if(options.addAndroidDownloads.hasKey("mediaScannable") && options.addAndroidDownloads.hasKey("mediaScannable") == true ) { + req.allowScanningByMediaScanner(); + } while (it.hasNextKey()) { String key = it.nextKey(); req.addRequestHeader(key, headers.getString(key)); @@ -636,16 +644,20 @@ public void onReceive(Context context, Intent intent) { return; } String contentUri = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); - if (contentUri != null) { + if ( contentUri != null && + options.addAndroidDownloads.hasKey("mime") && + options.addAndroidDownloads.getString("mime").contains("image")) { Uri uri = Uri.parse(contentUri); Cursor cursor = appCtx.getContentResolver().query(uri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null); - // use default destination of DownloadManager + + // use default destination of DownloadManager if (cursor != null) { cursor.moveToFirst(); filePath = cursor.getString(0); } } } + // When the file is not found in media content database, check if custom path exists if (options.addAndroidDownloads.hasKey("path")) { try { From 6bb7c65161c17e4961e28dee4b8ff0d359da03ff Mon Sep 17 00:00:00 2001 From: Jeff Hellman Date: Fri, 14 Jul 2017 01:15:53 -0600 Subject: [PATCH 06/20] Add support for TLS 1.2 when running Android 4 (#430) --- .../java/com/RNFetchBlob/RNFetchBlobReq.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java b/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java index 34dc2887c..8a81a832e 100644 --- a/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java +++ b/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java @@ -7,10 +7,12 @@ import android.content.IntentFilter; import android.database.Cursor; import android.net.Uri; +import android.os.Build; import android.util.Base64; import com.RNFetchBlob.Response.RNFetchBlobDefaultResp; import com.RNFetchBlob.Response.RNFetchBlobFileResp; +import com.facebook.common.logging.FLog; import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.Callback; import com.facebook.react.bridge.ReactApplicationContext; @@ -21,6 +23,7 @@ import com.facebook.react.bridge.WritableMap; import com.facebook.react.modules.core.DeviceEventManagerModule; import com.facebook.react.modules.network.OkHttpClientProvider; +import com.facebook.react.modules.network.TLSSocketFactory; import java.io.File; import java.io.FileOutputStream; @@ -35,11 +38,14 @@ import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; import java.util.ArrayList; +import java.util.List; import java.util.HashMap; + import java.util.concurrent.TimeUnit; import okhttp3.Call; import okhttp3.ConnectionPool; +import okhttp3.ConnectionSpec; import okhttp3.Headers; import okhttp3.Interceptor; import okhttp3.MediaType; @@ -48,6 +54,8 @@ import okhttp3.RequestBody; import okhttp3.Response; import okhttp3.ResponseBody; +import okhttp3.TlsVersion; + public class RNFetchBlobReq extends BroadcastReceiver implements Runnable { @@ -366,9 +374,10 @@ public Response intercept(Chain chain) throws IOException { clientBuilder.retryOnConnectionFailure(false); clientBuilder.followRedirects(options.followRedirect); clientBuilder.followSslRedirects(options.followRedirect); + clientBuilder.retryOnConnectionFailure(true); + OkHttpClient client = enableTls12OnPreLollipop(clientBuilder).build(); - OkHttpClient client = clientBuilder.retryOnConnectionFailure(true).build(); Call call = client.newCall(req); taskTable.put(taskId, call); call.enqueue(new okhttp3.Callback() { @@ -683,5 +692,28 @@ public void onReceive(Context context, Intent intent) { } } + public static OkHttpClient.Builder enableTls12OnPreLollipop(OkHttpClient.Builder client) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { + try { + client.sslSocketFactory(new TLSSocketFactory()); + + ConnectionSpec cs = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS) + .tlsVersions(TlsVersion.TLS_1_2) + .build(); + + List< ConnectionSpec > specs = new ArrayList < > (); + specs.add(cs); + specs.add(ConnectionSpec.COMPATIBLE_TLS); + specs.add(ConnectionSpec.CLEARTEXT); + + client.connectionSpecs(specs); + } catch (Exception exc) { + FLog.e("OkHttpClientProvider", "Error while enabling TLS 1.2", exc); + } + } + + return client; + } + } From b70a12455dd353517dc392a65d77f43e2f1938aa Mon Sep 17 00:00:00 2001 From: Ben Hsieh Date: Fri, 14 Jul 2017 15:34:11 +0800 Subject: [PATCH 07/20] Update README.md --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b315848b9..7680fab86 100644 --- a/README.md +++ b/README.md @@ -26,13 +26,13 @@ A project committed to making file access and data transfer easier and more effi * [Android Media Scanner, and Download Manager Support](#user-content-android-media-scanner-and-download-manager-support) * [Self-Signed SSL Server](#user-content-self-signed-ssl-server) * [Transfer Encoding](#user-content-transfer-encoding) - * [RNFetchBlob as Fetch](#user-content-rnfetchblob-as-fetch) + * [Drop-in Fetch Replacement](#user-content-drop-in-fetch-replacement) * [File System](#user-content-file-system) * [File access](#user-content-file-access) * [File stream](#user-content-file-stream) * [Manage cached files](#user-content-cache-file-management) * [Web API Polyfills](#user-content-web-api-polyfills) -* [Performance Tips](#user-content-performance-tipsd) +* [Performance Tips](#user-content-performance-tips) * [API References](https://github.com/wkh237/react-native-fetch-blob/wiki/Fetch-API) * [Caveats](#user-content-caveats) * [Development](#user-content-development) @@ -452,11 +452,11 @@ task.cancel((err) => { ... }) ``` -### RNFetchBlob as Fetch +### Drop-in Fetch Replacement 0.9.0 -If you have existing code that uses `whatwg-fetch`(the official **fetch**), you don't have to change them after 0.9.0, just use fetch replacement. The difference between Official fetch and fetch replacement is, official fetch uses [whatwg-fetch](https://github.com/github/fetch) js library which wraps XMLHttpRequest polyfill under the hood it's a great library for web developers, however that does not play very well with RN. Our implementation is simply a wrapper of RNFetchBlob.fetch and fs APIs, so you can access all the features we provide. +If you have existing code that uses `whatwg-fetch`(the official **fetch**), it's not necessary to replace them with `RNFetchblob.fetch`, you can simply use our **Fetch Replacement**. The difference between Official them is official fetch uses [whatwg-fetch](https://github.com/github/fetch) which wraps XMLHttpRequest polyfill under the hood. It's a great library for web developers, but does not play very well with RN. Our implementation is simply a wrapper of our `fetch` and `fs` APIs, so you can access all the features we provided. [See document and examples](https://github.com/wkh237/react-native-fetch-blob/wiki/Fetch-API#fetch-replacement) @@ -613,6 +613,8 @@ In `v0.5.0` we've added `writeStream` and `readStream`, which allows your app r When calling `readStream` method, you have to `open` the stream, and start to read data. When the file is large, consider using an appropriate `bufferSize` and `interval` to reduce the native event dispatching overhead (see [Performance Tips](#user-content-performance-tips)) +> The file stream event has a default throttle(10ms) and buffer size which preventing it cause too much overhead to main thread, yo can also [tweak these values](#user-content-performance-tips). + ```js let data = '' RNFetchBlob.fs.readStream( From 712c8a3a07044fb2ed9679eb5cfa010f553ad215 Mon Sep 17 00:00:00 2001 From: JoshB Date: Mon, 17 Jul 2017 05:22:33 -0700 Subject: [PATCH 08/20] [iOS] Fix for RNFetchBlob.writeChunk failing to write base64 encoded strings (#433) --- ios/RNFetchBlobFS.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ios/RNFetchBlobFS.m b/ios/RNFetchBlobFS.m index 9d4e00b0d..5e102d184 100644 --- a/ios/RNFetchBlobFS.m +++ b/ios/RNFetchBlobFS.m @@ -568,11 +568,11 @@ - (NSString *)openWithPath:(NSString *)destPath encode:(nullable NSString *)enco // Write file chunk into an opened stream - (void)writeEncodeChunk:(NSString *) chunk { - NSMutableData * decodedData = [NSData alloc]; + NSData * decodedData = nil; if([[self.encoding lowercaseString] isEqualToString:@"base64"]) { - decodedData = [[NSData alloc] initWithBase64EncodedData:chunk options:0]; - } - if([[self.encoding lowercaseString] isEqualToString:@"utf8"]) { + decodedData = [[NSData alloc] initWithBase64EncodedString:chunk options: NSDataBase64DecodingIgnoreUnknownCharacters]; + } + else if([[self.encoding lowercaseString] isEqualToString:@"utf8"]) { decodedData = [chunk dataUsingEncoding:NSUTF8StringEncoding]; } else if([[self.encoding lowercaseString] isEqualToString:@"ascii"]) { @@ -793,4 +793,4 @@ + (void) writeAssetToPath:(ALAssetRepresentation * )rep dest:(NSString *)dest return; } -@end +@end \ No newline at end of file From d83d8007a8e8cdddda368d78bb622a53a99b8d3b Mon Sep 17 00:00:00 2001 From: Ben Hsieh Date: Tue, 25 Jul 2017 09:57:53 +0800 Subject: [PATCH 09/20] Add missing API Blob.safeClose() --- polyfill/Blob.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/polyfill/Blob.js b/polyfill/Blob.js index 384ae8fd9..a91a897b6 100644 --- a/polyfill/Blob.js +++ b/polyfill/Blob.js @@ -130,6 +130,8 @@ export default class Blob extends EventTarget { // Blob data from file path else if(typeof data === 'string' && data.startsWith('RNFetchBlob-file://')) { log.verbose('create Blob cache file from file path', data) + // set this flag so that we know this blob is a wrapper of an existing file + this._isReference = true this._ref = String(data).replace('RNFetchBlob-file://', '') let orgPath = this._ref if(defer) @@ -282,6 +284,20 @@ export default class Blob extends EventTarget { }) } + safeClose() { + if(this._closed) + return Promise.reject('Blob has been released.) + this._closed = true + if(!this._isReference) { + return fs.unlink(this._ref).catch((err) => { + console.warn(err) + }) + } + else { + return Promise.resolve() + } + } + _invokeOnCreateEvent() { log.verbose('invoke create event', this._onCreated) this._blobCreated = true From d1d07d0922468ed812de5bc11d4ed4743589074b Mon Sep 17 00:00:00 2001 From: Hizoul Date: Wed, 2 Aug 2017 02:43:47 +0200 Subject: [PATCH 10/20] Fix Compilation Error in React Native 0.47.0 (#452) createJSModules was removedin React Native 0.47.0 and results in the attached Build Error. removing @Override fixes build (didn't remove function because I don't know if it should be kept for downard compatability?) ``` node_modules/react-native-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobPackage.java:23: error: method does not override or implement a method from a supertype @Override ^ 1 error Incremental compilation of 1 classes completed in 0.219 secs. :react-native-fetch-blob:compileReleaseJavaWithJavac FAILED FAILURE: Build failed with an exception. ``` --- android/src/main/java/com/RNFetchBlob/RNFetchBlobPackage.java | 1 - 1 file changed, 1 deletion(-) diff --git a/android/src/main/java/com/RNFetchBlob/RNFetchBlobPackage.java b/android/src/main/java/com/RNFetchBlob/RNFetchBlobPackage.java index 74e0224a7..48aac7ac3 100644 --- a/android/src/main/java/com/RNFetchBlob/RNFetchBlobPackage.java +++ b/android/src/main/java/com/RNFetchBlob/RNFetchBlobPackage.java @@ -20,7 +20,6 @@ public List createNativeModules(ReactApplicationContext reactConte return modules; } - @Override public List> createJSModules() { return Collections.emptyList(); } From 6bde5167b435e23e334377aa3bb62e8cf7c7e188 Mon Sep 17 00:00:00 2001 From: Ben Hsieh Date: Wed, 2 Aug 2017 23:03:16 +0800 Subject: [PATCH 11/20] Bump to 0.10.7 --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index a4524df60..0d88ec178 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-fetch-blob", - "version": "0.10.6", + "version": "0.10.7", "description": "A module provides upload, download, and files access API. Supports file stream read/write for process large files.", "main": "index.js", "scripts": { @@ -8,7 +8,7 @@ }, "dependencies": { "base-64": "0.1.0", - "glob": "^7.0.6" + "glob": "7.0.6" }, "keywords": [ "react-native", @@ -35,4 +35,4 @@ "Ben ", "" ] -} \ No newline at end of file +} From 50c157345f13725855e6405f91a1f544575cfd4e Mon Sep 17 00:00:00 2001 From: Ben Hsieh Date: Wed, 2 Aug 2017 23:13:10 +0800 Subject: [PATCH 12/20] Update PULL_REQUEST_TEMPLATE --- .github/PULL_REQUEST_TEMPLATE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE b/.github/PULL_REQUEST_TEMPLATE index edadaa9b6..cef8ed2af 100644 --- a/.github/PULL_REQUEST_TEMPLATE +++ b/.github/PULL_REQUEST_TEMPLATE @@ -1,5 +1,5 @@ Thank you for making a pull request ! Just a gentle reminder :) 1. If the PR is offering a feature please make the request to our "Feature Branch" 0.11.0 -2. Bug fix request to "Bug Fix Branch" 0.10.7 +2. Bug fix request to "Bug Fix Branch" 0.10.8 3. Correct README.md can directly to master From 55009f148288f6471e7e084db3881bbdd1d7d98a Mon Sep 17 00:00:00 2001 From: Ben Hsieh Date: Thu, 3 Aug 2017 09:34:37 +0800 Subject: [PATCH 13/20] Correct unterminated string #455 --- polyfill/Blob.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polyfill/Blob.js b/polyfill/Blob.js index a91a897b6..53662a798 100644 --- a/polyfill/Blob.js +++ b/polyfill/Blob.js @@ -286,7 +286,7 @@ export default class Blob extends EventTarget { safeClose() { if(this._closed) - return Promise.reject('Blob has been released.) + return Promise.reject('Blob has been released.') this._closed = true if(!this._isReference) { return fs.unlink(this._ref).catch((err) => { From 9ab4ebb72e648156b2af60578de112022f856fb4 Mon Sep 17 00:00:00 2001 From: Ben Hsieh Date: Thu, 3 Aug 2017 09:37:08 +0800 Subject: [PATCH 14/20] bump to 0.10.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0d88ec178..a93dba81d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-fetch-blob", - "version": "0.10.7", + "version": "0.10.8", "description": "A module provides upload, download, and files access API. Supports file stream read/write for process large files.", "main": "index.js", "scripts": { From 1336555d79014a181ab79350434e016ea1bc8324 Mon Sep 17 00:00:00 2001 From: Ben Hsieh Date: Thu, 3 Aug 2017 09:42:16 +0800 Subject: [PATCH 15/20] Update PULL_REQUEST_TEMPLATE --- .github/PULL_REQUEST_TEMPLATE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE b/.github/PULL_REQUEST_TEMPLATE index cef8ed2af..b03e3e8e3 100644 --- a/.github/PULL_REQUEST_TEMPLATE +++ b/.github/PULL_REQUEST_TEMPLATE @@ -1,5 +1,5 @@ Thank you for making a pull request ! Just a gentle reminder :) 1. If the PR is offering a feature please make the request to our "Feature Branch" 0.11.0 -2. Bug fix request to "Bug Fix Branch" 0.10.8 +2. Bug fix request to "Bug Fix Branch" 0.10.9 3. Correct README.md can directly to master From 2aea0b58e99581000d7336697e70b3bba7670a50 Mon Sep 17 00:00:00 2001 From: grylance Date: Wed, 9 Aug 2017 16:12:33 +0100 Subject: [PATCH 16/20] Fix path argument in iOS excludeFromBackupKey (#473) --- ios.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios.js b/ios.js index 566b424e2..340ef04cf 100644 --- a/ios.js +++ b/ios.js @@ -43,7 +43,7 @@ function openDocument(path:string, scheme:string) { * @param {string} url URL of the resource, only file URL is supported * @return {Promise} */ -function excludeFromBackupKey(url:string) { +function excludeFromBackupKey(path:string) { return RNFetchBlob.excludeFromBackupKey('file://' + path); } From 821eeb0f9db1736009ee791c14298ef72144a825 Mon Sep 17 00:00:00 2001 From: Kota Furusawa Date: Thu, 24 Aug 2017 10:02:20 +0800 Subject: [PATCH 17/20] Fix README (#501) remove extra space --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7680fab86..3c7d24a59 100644 --- a/README.md +++ b/README.md @@ -236,7 +236,7 @@ RNFetchBlob console.log('The file saved to ', res.path()) // Beware that when using a file path as Image source on Android, // you must prepend "file://"" before the file path - imageView = + imageView = }) ``` From c7b9e2e088dcbeeffaa30c0d5a68565c2f963aa5 Mon Sep 17 00:00:00 2001 From: Tom Bailey Date: Wed, 20 Sep 2017 14:18:46 +0100 Subject: [PATCH 18/20] Handle content URIs correctly --- .../java/com/RNFetchBlob/RNFetchBlobBody.java | 34 +++++++++++++++++++ .../com/RNFetchBlob/RNFetchBlobConst.java | 1 + index.js | 6 +++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java b/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java index 8146a99cf..55feb5381 100644 --- a/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java +++ b/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java @@ -1,5 +1,6 @@ package com.RNFetchBlob; +import android.net.Uri; import android.util.Base64; import com.facebook.react.bridge.Arguments; @@ -21,8 +22,13 @@ import okhttp3.RequestBody; import okio.BufferedSink; +import static com.RNFetchBlob.RNFetchBlobConst.CONTENT_PREFIX; + public class RNFetchBlobBody extends RequestBody{ + private static final int BYTE_SKIP_LENGTH = 1024 * 1024; //1024 * 1024 = 1MB + + InputStream requestStream; long contentLength = 0; ReadableArray form; @@ -160,6 +166,14 @@ private InputStream getReuqestStream() throws Exception { } } } + else if (rawBody.startsWith(RNFetchBlobConst.CONTENT_PREFIX)) { + try { + String contentUri = rawBody.substring(RNFetchBlobConst.CONTENT_PREFIX.length()); + return RNFetchBlob.RCTContext.getContentResolver().openInputStream(Uri.parse(contentUri)); + } catch (IOException e) { + throw new Exception("error when getting request stream from content uri: " +e.getLocalizedMessage()); + } + } // base 64 encoded else { try { @@ -226,6 +240,16 @@ private File createMultipartBodyCache() throws IOException { } } } + else if (data.startsWith(RNFetchBlobConst.CONTENT_PREFIX)) { + try { + String contentUri = data.substring(RNFetchBlobConst.CONTENT_PREFIX.length()); + InputStream inputStream = ctx.getContentResolver().openInputStream(Uri.parse(contentUri)); + + pipeStreamToFileStream(inputStream, os); + } catch (IOException e) { + RNFetchBlobUtils.emitWarningEvent(e.getLocalizedMessage()); + } + } // base64 embedded file content else { byte[] b = Base64.decode(data, 0); @@ -324,6 +348,16 @@ else if (field.filename != null) { File file = new File(RNFetchBlobFS.normalizePath(orgPath)); total += file.length(); } + } else if (data.startsWith(RNFetchBlobConst.CONTENT_PREFIX)) { + try { + String contentUri = data.substring(RNFetchBlobConst.CONTENT_PREFIX.length()); + RNFetchBlobUtils.emitWarningEvent("contentUri=" + contentUri); + + long length = ctx.getContentResolver().openInputStream(Uri.parse(contentUri)).available(); + total += length; + } catch (IOException e) { + RNFetchBlobUtils.emitWarningEvent(e.getLocalizedMessage()); + } } // base64 embedded file content else { diff --git a/android/src/main/java/com/RNFetchBlob/RNFetchBlobConst.java b/android/src/main/java/com/RNFetchBlob/RNFetchBlobConst.java index 015cc8954..fe2424432 100644 --- a/android/src/main/java/com/RNFetchBlob/RNFetchBlobConst.java +++ b/android/src/main/java/com/RNFetchBlob/RNFetchBlobConst.java @@ -14,5 +14,6 @@ public class RNFetchBlobConst { public static final String RNFB_RESPONSE_UTF8 = "utf8"; public static final String RNFB_RESPONSE_PATH = "path"; public static final Integer GET_CONTENT_INTENT = 99900; + public static final String CONTENT_PREFIX = "RNFetchBlob-content://"; } diff --git a/index.js b/index.js index c8ed1a9f6..2daccb2de 100644 --- a/index.js +++ b/index.js @@ -79,7 +79,11 @@ if(!RNFetchBlob || !RNFetchBlob.fetchBlobForm || !RNFetchBlob.fetchBlob) { } function wrap(path:string):string { - return 'RNFetchBlob-file://' + path + if (path.startsWith('content://')) { + return 'RNFetchBlob-content://' + path + } else { + return 'RNFetchBlob-file://' + path + } } /** From 703880bb5bac40403cba037db294e2952a1b0ec0 Mon Sep 17 00:00:00 2001 From: Tom Bailey Date: Fri, 29 Sep 2017 11:14:38 +0100 Subject: [PATCH 19/20] Remove unused warning event --- android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java b/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java index 55feb5381..7eb1717d3 100644 --- a/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java +++ b/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java @@ -351,8 +351,6 @@ else if (field.filename != null) { } else if (data.startsWith(RNFetchBlobConst.CONTENT_PREFIX)) { try { String contentUri = data.substring(RNFetchBlobConst.CONTENT_PREFIX.length()); - RNFetchBlobUtils.emitWarningEvent("contentUri=" + contentUri); - long length = ctx.getContentResolver().openInputStream(Uri.parse(contentUri)).available(); total += length; } catch (IOException e) { From c7f0c2301e4f4288fa95431a9cdb85ec7f11af30 Mon Sep 17 00:00:00 2001 From: Tom Bailey Date: Wed, 24 Jan 2018 11:45:56 +0000 Subject: [PATCH 20/20] Don't enforce app label on library consumer --- android/src/main/AndroidManifest.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 807904417..9f823199f 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,9 +1,3 @@ - - - - -