react-native-blob-util 0.17.1 → 0.17.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -27,7 +27,7 @@ react-native-blob-util version **0.10.16** and up is only compatible with react
27
27
  - JSON stream supported base on [Oboe.js](https://github.com/jimhigson/oboe.js/) @jimhigson
28
28
 
29
29
  ## React Native New Architecture
30
- With Reacht Native 0.68.0 the switch to enable the new aritechture was introduced.
30
+ With React Native 0.68.0 the switch to enable the new aritechture was introduced.
31
31
  Starting with version 0.17.0 this library introduces support for the new architecture as well. Of course the old architecture will still be supproted.
32
32
  Further information about it and how to use it you can find here: https://reactnative.dev/docs/next/the-new-architecture/landing-page
33
33
 
@@ -92,14 +92,21 @@ After `0.10.3` you can install this package directly from Github
92
92
  npm install --save github:RonRadtke/react-native-blob-util#<branch_name>
93
93
  ```
94
94
 
95
+ **iOS**
96
+
97
+ When using the package from npm, run `pod install` from the `ios` directory:
98
+
99
+ ```sh
100
+ cd ios; pod install; cd ..
101
+ ```
102
+
95
103
  **Okhttp**
96
104
 
97
105
  For using the library okhttp3 is required. It's in general included in react-native. The library uses the okhttp version shipped with react-native or used by your app. For very old devices android devices okhttp 3.12 can be used.
98
106
 
99
107
  **Manually Link Native Modules**
100
108
 
101
- If you're using RN 0.60 or higher, manuall linking should not be required anymore.
102
-
109
+ If you're using RN 0.60 or higher, manual linking should not be required anymore.
103
110
 
104
111
  If automatically linking doesn't work for you, see instructions on [manually linking](https://github.com/RonRadtke/react-native-blob-util/wiki/Manually-Link-Package#index).
105
112
 
@@ -658,14 +665,14 @@ Android 10 introduced scoped storage and thus new APIs to store files to Documen
658
665
 
659
666
  #### CopyToMediaStore
660
667
 
661
- Copies an existing file from the internal Storage to the Media Store. <br> An exmaple for downloading a file and storing it to the `downloads` collection
668
+ Copies an existing file from the internal Storage to the Media Store. <br> An example for downloading a file and storing it to the `downloads` collection
662
669
 
663
670
  ```js
664
671
  ReactNativeBlobUtil
665
672
  .config({
666
673
  fileCache: true
667
674
  })
668
- .fetch('GET', 'https://example.de/image.png', {'Accept': 'application/octet-stream'}, JSON.stringify(dat))
675
+ .fetch('GET', 'https://example.de/image.png')
669
676
  .then(async (res) => {
670
677
  let result = await ReactNativeBlobUtil.MediaCollection.copyToMediaStore({
671
678
  name: filename, // name of the file
@@ -59,6 +59,10 @@ android {
59
59
  proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
60
60
  }
61
61
  }
62
+ compileOptions {
63
+ sourceCompatibility JavaVersion.VERSION_1_8
64
+ targetCompatibility JavaVersion.VERSION_1_8
65
+ }
62
66
  lintOptions {
63
67
  abortOnError false
64
68
  }
@@ -157,4 +161,4 @@ afterEvaluate { project ->
157
161
  }
158
162
  }
159
163
  }
160
- }
164
+ }
@@ -355,7 +355,11 @@ class ReactNativeBlobUtilFS {
355
355
  } else {
356
356
  res.put("SDCardApplicationDir", "");
357
357
  }
358
+ } else {
359
+ res.put("SDCardDir", "");
360
+ res.put("SDCardApplicationDir", "");
358
361
  }
362
+
359
363
  res.put("MainBundleDir", ctx.getApplicationInfo().dataDir);
360
364
 
361
365
  // TODO Change me with the correct path
@@ -376,7 +380,20 @@ class ReactNativeBlobUtilFS {
376
380
  static Map<String, Object> getLegacySystemfolders(ReactApplicationContext ctx) {
377
381
  Map<String, Object> res = new HashMap<>();
378
382
 
379
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) return ReactNativeBlobUtilFS.getSystemfolders(ctx);
383
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
384
+ res = ReactNativeBlobUtilFS.getSystemfolders(ctx);
385
+
386
+ // Include legacy folders anyway, since on the new arch compatibility between the spec and the turbomodule is enforced
387
+ res.put("LegacyDCIMDir", "");
388
+ res.put("LegacyPictureDir", "");
389
+ res.put("LegacyMusicDir", "");
390
+ res.put("LegacyDownloadDir", "");
391
+ res.put("LegacyMovieDir", "");
392
+ res.put("LegacyRingtoneDir", "");
393
+ res.put("LegacySDCardDir", "");
394
+
395
+ return res;
396
+ }
380
397
 
381
398
  res.put("LegacyDCIMDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath());
382
399
  res.put("LegacyPictureDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
@@ -388,6 +405,8 @@ class ReactNativeBlobUtilFS {
388
405
  String state = Environment.getExternalStorageState();
389
406
  if (state.equals(Environment.MEDIA_MOUNTED)) {
390
407
  res.put("LegacySDCardDir", Environment.getExternalStorageDirectory().getAbsolutePath());
408
+ } else {
409
+ res.put("LegacySDCardDir", "");
391
410
  }
392
411
 
393
412
  return res;
@@ -155,8 +155,8 @@ public class ReactNativeBlobUtilReq extends BroadcastReceiver implements Runnabl
155
155
  }
156
156
 
157
157
  public static void cancelTask(String taskId) {
158
- if (taskTable.containsKey(taskId)) {
159
- Call call = taskTable.get(taskId);
158
+ Call call = taskTable.get(taskId);
159
+ if (call != null) {
160
160
  call.cancel();
161
161
  taskTable.remove(taskId);
162
162
  }
@@ -0,0 +1,10 @@
1
+ const CANCELED_FETCH_ERROR_NAME = 'ReactNativeBlobUtilCanceledFetch'
2
+
3
+ class CanceledFetchError extends Error {
4
+ constructor(message) {
5
+ super(message);
6
+ this.name = CANCELED_FETCH_ERROR_NAME
7
+ }
8
+ }
9
+
10
+ export default CanceledFetchError
@@ -18,6 +18,14 @@ export interface Spec extends TurboModule {
18
18
  SDCardDir: string,
19
19
  SDCardApplicationDir: string,
20
20
  DCIMDir: string,
21
+ // Android Only Legacy Constants
22
+ LegacyDCIMDir: string,
23
+ LegacyPictureDir: string,
24
+ LegacyMusicDir: string,
25
+ LegacyDownloadDir: string,
26
+ LegacyMovieDir: string,
27
+ LegacyRingtoneDir: string,
28
+ LegacySDCardDir: string,
21
29
  |};
22
30
 
23
31
  +fetchBlobForm: (options: Object, taskId: string, method: string, url: string, headers: Object, form: Array<any>, callback: (value: Array<any>) => void) => void;
package/fetch.js CHANGED
@@ -4,6 +4,7 @@ import fs from "./fs";
4
4
  import getUUID from "./utils/uuid";
5
5
  import {DeviceEventEmitter} from "react-native";
6
6
  import {FetchBlobResponse} from "./class/ReactNativeBlobUtilBlobResponse";
7
+ import CanceledFetchError from "./class/ReactNativeBlobUtilCanceledFetchError";
7
8
  import ReactNativeBlobUtil from "./codegenSpecs/NativeBlobUtils";
8
9
 
9
10
  const emitter = DeviceEventEmitter;
@@ -328,7 +329,7 @@ export function fetch(...args: any): Promise {
328
329
  subscriptionUpload.remove();
329
330
  stateEvent.remove();
330
331
  ReactNativeBlobUtil.cancelRequest(taskId, fn);
331
- promiseReject(new Error("canceled"));
332
+ promiseReject(new CanceledFetchError("canceled"));
332
333
  };
333
334
  promise.taskId = taskId;
334
335
 
package/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export const ReactNativeBlobUtil: ReactNativeBlobUtilStatic;
7
7
  export type ReactNativeBlobUtil = ReactNativeBlobUtilStatic;
8
8
  export default ReactNativeBlobUtil;
9
9
  import {filedescriptor} from './types';
10
+ import CanceledFetchError from './class/ReactNativeBlobUtilCanceledFetchError'
10
11
 
11
12
  interface ReactNativeBlobUtilStatic {
12
13
  fetch(method: Methods, url: string, headers?: { [key: string]: string }, body?: any
@@ -29,6 +30,7 @@ interface ReactNativeBlobUtilStatic {
29
30
  polyfill: Polyfill;
30
31
  // this require external module https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/oboe
31
32
  JSONStream: any;
33
+ CanceledFetchError: CanceledFetchError
32
34
  }
33
35
 
34
36
  export interface Polyfill {
package/index.js CHANGED
@@ -15,6 +15,7 @@ import ios from './ios';
15
15
  import JSONStream from './json-stream';
16
16
  import {config, fetch} from './fetch';
17
17
  import URIUtil from "./utils/uri";
18
+ import CanceledFetchError from "./class/ReactNativeBlobUtilCanceledFetchError";
18
19
 
19
20
  const {
20
21
  ReactNativeBlobUtilSession,
@@ -70,5 +71,6 @@ export default {
70
71
  wrap,
71
72
  polyfill,
72
73
  JSONStream,
73
- MediaCollection
74
+ MediaCollection,
75
+ CanceledFetchError
74
76
  };
@@ -12,7 +12,7 @@
12
12
  #import "ReactNativeBlobUtilProgress.h"
13
13
 
14
14
  #if RCT_NEW_ARCH_ENABLED
15
- #import "ReactNativeBlobUtilSpec.h"
15
+ #import <ReactNativeBlobUtilSpec/ReactNativeBlobUtilSpec.h>
16
16
  #endif
17
17
 
18
18
  __strong RCTEventDispatcher * eventDispatcherRef;
@@ -31,6 +31,7 @@ dispatch_queue_t fsQueue;
31
31
 
32
32
  @synthesize filePathPrefix;
33
33
  @synthesize documentController;
34
+ @synthesize bridge;
34
35
 
35
36
  - (dispatch_queue_t) methodQueue {
36
37
  if(commonTaskQueue == nil)
@@ -67,7 +68,7 @@ RCT_EXPORT_MODULE();
67
68
  [[NSFileManager defaultManager] createDirectoryAtPath:[ReactNativeBlobUtilFS getTempPath] withIntermediateDirectories:YES attributes:nil error:NULL];
68
69
  }
69
70
  dispatch_async(dispatch_get_main_queue(), ^{
70
- eventDispatcherRef = [ReactNativeBlobUtil getRCTEventDispatcher];
71
+ eventDispatcherRef = bridge.eventDispatcher;
71
72
  [ReactNativeBlobUtilNetwork emitExpiredTasks: eventDispatcherRef];
72
73
  });
73
74
 
@@ -95,6 +96,14 @@ RCT_EXPORT_MODULE();
95
96
  @"SDCardDir": @"",
96
97
  @"SDCardApplicationDir": @"",
97
98
  @"DCIMDir": @"",
99
+ // Android only legacy constants
100
+ @"LegacyDCIMDir": @"",
101
+ @"LegacyPictureDir": @"",
102
+ @"LegacyMusicDir": @"",
103
+ @"LegacyDownloadDir": @"",
104
+ @"LegacyMovieDir": @"",
105
+ @"LegacyRingtoneDir": @"",
106
+ @"LegacySDCardDir": @"",
98
107
  };
99
108
  }
100
109
 
@@ -677,7 +686,7 @@ RCT_EXPORT_METHOD(hash:(NSString *)path
677
686
  }
678
687
 
679
688
  #pragma mark - fs.readStream
680
- RCT_EXPORT_METHOD(readStream:(NSString *)path withEncoding:(NSString *)encoding bufferSize:(int)bufferSize tick:(int)tick streamId:(NSString *)streamId)
689
+ RCT_EXPORT_METHOD(readStream:(NSString *)path encoding:(NSString *)encoding bufferSize:(int)bufferSize tick:(int)tick streamId:(NSString *)streamId)
681
690
  {
682
691
  if(bufferSize == 0) {
683
692
  if([[encoding lowercaseString] isEqualToString:@"base64"])
@@ -902,7 +911,7 @@ RCT_EXPORT_METHOD(emitExpiredEvent:(RCTResponseSenderBlock)callback)
902
911
  }
903
912
  - (void)copyToMediaStore:(NSDictionary *)filedata
904
913
  mt:(NSString *) mt
905
- path:(NSString *)
914
+ path:(NSString *) path
906
915
  resolve:(RCTPromiseResolveBlock)resolve
907
916
  reject:(RCTPromiseRejectBlock)reject
908
917
  {
@@ -955,7 +964,6 @@ RCT_EXPORT_METHOD(emitExpiredEvent:(RCTResponseSenderBlock)callback)
955
964
  reject(@"ENOT_SUPPORTED", @"This method is not supported on iOS", nil);
956
965
  }
957
966
 
958
-
959
967
  # pragma mark - New Architecture
960
968
  #if RCT_NEW_ARCH_ENABLED
961
969
  - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
@@ -411,9 +411,9 @@ NSMutableDictionary *fileStreams = nil;
411
411
  [fileHandle closeFile];
412
412
  }
413
413
  else {
414
- if (![content writeToFile:path atomically:YES]) {
414
+ if (![content writeToFile:path options:NSDataWritingAtomic error:&err]) {
415
415
  fm = nil;
416
- return reject(@"EUNSPECIFIED", [NSString stringWithFormat:@"File '%@' could not be written.", path], nil);
416
+ return reject(@"EUNSPECIFIED", [NSString stringWithFormat:@"File '%@' could not be written; error: %@", path, [err description]], err);
417
417
  }
418
418
  }
419
419
  fm = nil;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-blob-util",
3
- "version": "0.17.1",
3
+ "version": "0.17.3",
4
4
  "description": "A module provides upload, download, and files access API. Supports file stream read/write for process large files.",
5
5
  "main": "index",
6
6
  "scripts": {
package/polyfill/Fetch.js CHANGED
@@ -40,7 +40,10 @@ class ReactNativeBlobUtilFetchPolyfill {
40
40
  log.verbose('convert FormData to blob body');
41
41
  promise = Blob.build(body).then((b) => {
42
42
  blobCache = b;
43
- options.headers['Content-Type'] = 'multipart/form-data;boundary=' + b.multipartBoundary;
43
+
44
+ const contentType = 'multipart/form-data;boundary=' + b.multipartBoundary
45
+ options.headers['Content-Type'] = contentType;
46
+ options.headers['content-type'] = contentType;
44
47
  return Promise.resolve(URIUtil.wrap(b._ref));
45
48
  });
46
49
  }
@@ -60,6 +60,7 @@
60
60
  <PlatformToolset>v140</PlatformToolset>
61
61
  <PlatformToolset Condition="'$(VisualStudioVersion)' == '15.0'">v141</PlatformToolset>
62
62
  <PlatformToolset Condition="'$(VisualStudioVersion)' == '16.0'">v142</PlatformToolset>
63
+ <PlatformToolset Condition="'$(VisualStudioVersion)' == '17.0'">v142</PlatformToolset>
63
64
  <CharacterSet>Unicode</CharacterSet>
64
65
  <GenerateManifest>false</GenerateManifest>
65
66
  </PropertyGroup>
@@ -177,4 +178,4 @@
177
178
  <LinkLibraryDependencies>true</LinkLibraryDependencies>
178
179
  </ProjectReference>
179
180
  </ItemGroup>
180
- </Project>
181
+ </Project>