diff --git a/.flowconfig b/.flowconfig index 3f410a6..f016288 100644 --- a/.flowconfig +++ b/.flowconfig @@ -1,5 +1,5 @@ [ignore] -.*/node_modules/.* +.*/node_modules/react_native/.* [include] @@ -8,4 +8,4 @@ [options] [version] -0.27.0 +0.28.0 diff --git a/FS.common.js b/FS.common.js index a62bc76..c5a9447 100644 --- a/FS.common.js +++ b/FS.common.js @@ -272,19 +272,7 @@ var RNFS = { return RNFSManager.appendFile(filepath, b64); }, - downloadFile(options: DownloadFileOptions): Promise { - if (arguments.length > 1) { - console.warn('Deprecated: Please see updated docs for `downloadFile`'); - - options = { - fromUrl: arguments[0], - toFile: arguments[1], - begin: arguments[2], - progress: arguments[3], - background: false - }; - } - + downloadFile(options: DownloadFileOptions): { jobId: number, promise: Promise } { if (typeof options !== 'object') throw new Error('downloadFile: Invalid value for argument `options`'); if (typeof options.fromUrl !== 'string') throw new Error('downloadFile: Invalid value for property `fromUrl`'); if (typeof options.toFile !== 'string') throw new Error('downloadFile: Invalid value for property `toFile`'); @@ -312,13 +300,23 @@ var RNFS = { progressDivider: options.progressDivider || 0 }; - return RNFSManager.downloadFile(bridgeOptions).then(res => { - subscriptions.forEach(sub => sub.remove()); - return res; - }); + return { + jobId, + promise: RNFSManager.downloadFile(bridgeOptions).then(res => { + subscriptions.forEach(sub => sub.remove()); + return res; + }) + }; }, - uploadFiles(options: UploadFileOptions): Promise { + uploadFiles(options: UploadFileOptions): { jobId: number, promise: Promise } { + if (!RNFSManager.uploadFiles) { + return { + jobId: -1, + promise: Promise.reject(new Error('`uploadFiles` is unsupported on this platform')) + }; + } + var jobId = getJobId(); var subscriptions = []; @@ -354,10 +352,13 @@ var RNFS = { method: options.method || 'POST' }; - return RNFSManager.uploadFiles(bridgeOptions).then(res => { - subscriptions.forEach(sub => sub.remove()); - return res; - }); + return { + jobId, + promise: RNFSManager.uploadFiles(bridgeOptions).then(res => { + subscriptions.forEach(sub => sub.remove()); + return res; + }) + }; }, MainBundlePath: RNFSManager.RNFSMainBundlePath, diff --git a/README.md b/README.md index 0c3fd6b..48032bd 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,9 @@ Native filesystem access for react-native - Removed attributes from `writeFile` and `appendFile` for iOS / Android consistency - `downloadFile` takes `options` object rather than parameters - `stopDownload` will cause the rejection of promise returned by `downloadFile` -- `uploadFile` promise result `response` property is now `body` +- `uploadFiles` promise result `response` property is now `body` - A boolean is no longer returned from any method except `exists` +- `downloadFile` and `uploadFiles` return an object of the form `{ jobId: number, promise: Promise }` ## Usage (iOS) @@ -242,7 +243,7 @@ RNFS.uploadFiles({ }, begin: uploadBegin, progress: uploadProgress -}).then((response) => { +}).promise.then((response) => { if (response.statusCode == 200) { console.log('FILES UPLOADED!'); // response.statusCode, response.headers, response.body } else { @@ -345,7 +346,7 @@ Create a directory at `filepath`. Automatically creates parents and does not thr (IOS only): If `excludeFromBackup` is true, then `NSURLIsExcludedFromBackupKey` attribute will be set. Apple will *reject* apps for storing offline cache data that does not have this attribute. -### `downloadFile(options: DownloadFileOptions): Promise` +### `downloadFile(options: DownloadFileOptions): { jobId: number, promise: Promise }` ``` type DownloadFileOptions = { @@ -405,7 +406,7 @@ If `progressDivider` = 0, you will receive all `progressCallback` calls, default Abort the current download job with this ID. The partial file will remain on the filesystem. -### (iOS only) `uploadFiles(options: UploadFileOptions): Promise` +### (iOS only) `uploadFiles(options: UploadFileOptions): { jobId: number, promise: Promise }` `options` (`Object`) - An object containing named parameters