react-native-blob-util 0.16.0 → 0.16.1

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
@@ -165,7 +165,7 @@ If you are going to use the `wifiOnly` flag, you need to add this to `AndroidMan
165
165
 
166
166
  **Grant Access Permission for Android 6.0**
167
167
 
168
- Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app. So adding permissions in `AndroidManifest.xml` won't work for Android 6.0+ devices. To grant permissions in runtime, you might use [PermissionAndroid API](https://facebook.github.io/react-native/docs/permissionsandroid.html).
168
+ Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app. So adding permissions in `AndroidManifest.xml` won't work for Android 6.0+ devices. To grant permissions in runtime, you might use [PermissionAndroid API](https://facebook.github.io/react-native/docs/permissionsandroid).
169
169
 
170
170
  ## Usage
171
171
 
@@ -185,6 +185,7 @@ public class ReactNativeBlobUtilReq extends BroadcastReceiver implements Runnabl
185
185
  DownloadManager downloadManager = (DownloadManager) appCtx.getSystemService(Context.DOWNLOAD_SERVICE);
186
186
 
187
187
  DownloadManager.Query query = new DownloadManager.Query();
188
+ query.setFilterById(downloadManagerId);
188
189
 
189
190
  Cursor cursor = downloadManager.query(query);
190
191
 
@@ -197,7 +198,7 @@ public class ReactNativeBlobUtilReq extends BroadcastReceiver implements Runnabl
197
198
  cursor.close();
198
199
 
199
200
  ReactNativeBlobUtilProgressConfig reportConfig = getReportProgress(taskId);
200
- float progress = (total != -1) ? written / total : 0;
201
+ float progress = (total > 0) ? written / total : 0;
201
202
 
202
203
  if (reportConfig != null && reportConfig.shouldReport(progress /* progress */)) {
203
204
  WritableMap args = Arguments.createMap();
package/index.js CHANGED
@@ -56,9 +56,9 @@ if (!ReactNativeBlobUtil || !ReactNativeBlobUtil.fetchBlobForm || !ReactNativeBl
56
56
  }
57
57
 
58
58
  export {ReactNativeBlobUtilConfig, ReactNativeBlobUtilResponseInfo, ReactNativeBlobUtilStream} from './types';
59
- export URIUtil from './utils/uri';
59
+ export { URIUtil } from './utils/uri';
60
60
  export {FetchBlobResponse} from './class/ReactNativeBlobUtilBlobResponse';
61
- export getUUID from './utils/uuid';
61
+ export { getUUID } from './utils/uuid';
62
62
  export default {
63
63
  fetch,
64
64
  base64,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-blob-util",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
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.js",
6
6
  "scripts": {
@@ -35,11 +35,16 @@
35
35
  "wkh237 <xeiyan@gmail.com>"
36
36
  ],
37
37
  "devDependencies": {
38
- "react-native": "^0.64.2",
38
+ "react": "16.13.1",
39
+ "react-native": "^0.68.2",
39
40
  "@typescript-eslint/parser": "^3.4.0",
40
41
  "@react-native-community/eslint-config": "^3.0.0",
41
42
  "eslint-config-defaults": "^9.0.0",
42
43
  "eslint-plugin-react": "^7.24.0",
43
44
  "eslint": "^6.8.0"
45
+ },
46
+ "peerDependencies": {
47
+ "react": "*",
48
+ "react-native": "*"
44
49
  }
45
50
  }
@@ -170,6 +170,12 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget {
170
170
  log.verbose('sending request with args', _method, _url, _headers, body);
171
171
  log.verbose(typeof body, body instanceof FormData);
172
172
 
173
+ if (body instanceof FormData) {
174
+ log.debug('creating blob and setting header from FormData instance');
175
+ body = new Blob(body);
176
+ this._headers['Content-Type'] = `multipart/form-data; boundary=${body.multipartBoundary}`;
177
+ }
178
+
173
179
  if (body instanceof Blob) {
174
180
  log.debug('sending blob body', body._blobCreated);
175
181
  promise = new Promise((resolve, reject) => {
@@ -1,7 +0,0 @@
1
- module.exports = {
2
- dependency: {
3
- hooks: {
4
- prelink: 'node ./node_modules/react-native-blob-util/scripts/prelink.js',
5
- },
6
- },
7
- };
@@ -1,71 +0,0 @@
1
- try {
2
- var fs = require('fs');
3
- var glob = require('glob');
4
- var addAndroidPermissions = process.env.RNFB_ANDROID_PERMISSIONS == 'true';
5
- var MANIFEST_PATH = glob.sync(process.cwd() + '/android/app/src/main/**/AndroidManifest.xml')[0];
6
- var PACKAGE_JSON = process.cwd() + '/package.json';
7
- var package = JSON.parse(fs.readFileSync(PACKAGE_JSON));
8
- var APP_NAME = package.name;
9
- var PACKAGE_GRADLE = process.cwd() + '/node_modules/react-native-blob-util/android/build.gradle'
10
- var VERSION = checkVersion();
11
-
12
- console.log('ReactNativeBlobUtil detected app version => ' + VERSION);
13
-
14
- if(VERSION < 0.28) {
15
- console.log('You project version is '+ VERSION + ' which may not compatible to react-native-blob-util 7.0+, please consider upgrade your application template to react-native 0.27+.')
16
- // add OkHttp3 dependency fo pre 0.28 project
17
- var main = fs.readFileSync(PACKAGE_GRADLE);
18
- console.log('adding OkHttp3 dependency to pre 0.28 project .. ')
19
- main = String(main).replace('//{ReactNativeBlobUtil_PRE_0.28_DEPDENDENCY}', "compile 'com.squareup.okhttp3:okhttp:3.4.1'");
20
- fs.writeFileSync(PACKAGE_GRADLE, main);
21
- console.log('adding OkHttp3 dependency to pre 0.28 project .. ok')
22
- }
23
-
24
- console.log('Add Android permissions => ' + (addAndroidPermissions == "true"))
25
-
26
- if(addAndroidPermissions) {
27
-
28
- // set file access permission for Android < 6.0
29
- fs.readFile(MANIFEST_PATH, function(err, data) {
30
-
31
- if(err)
32
- console.log('failed to locate AndroidManifest.xml file, you may have to add file access permission manually.');
33
- else {
34
-
35
- console.log('ReactNativeBlobUtil patching AndroidManifest.xml .. ');
36
- // append fs permission
37
- data = String(data).replace(
38
- '<uses-permission android:name="android.permission.INTERNET" />',
39
- '<uses-permission android:name="android.permission.INTERNET" />\n <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> '
40
- )
41
- // append DOWNLOAD_COMPLETE intent permission
42
- data = String(data).replace(
43
- '<category android:name="android.intent.category.LAUNCHER" />',
44
- '<category android:name="android.intent.category.LAUNCHER" />\n <action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>'
45
- )
46
- fs.writeFileSync(MANIFEST_PATH, data);
47
- console.log('ReactNativeBlobUtil patching AndroidManifest.xml .. ok');
48
-
49
- }
50
-
51
- })
52
- }
53
- else {
54
- console.log(
55
- '\033[95mreact-native-blob-util \033[97mwill not automatically add Android permissions after \033[92m0.9.4 '+
56
- '\033[97mplease run the following command if you want to add default permissions :\n\n' +
57
- '\033[96m\tRNFB_ANDROID_PERMISSIONS=true react-native link \n')
58
- }
59
-
60
- function checkVersion() {
61
- console.log('ReactNativeBlobUtil checking app version ..');
62
- return parseFloat(/\d\.\d+(?=\.)/.exec(package.dependencies['react-native']));
63
- }
64
-
65
- } catch(err) {
66
- console.log(
67
- '\033[95mreact-native-blob-util\033[97m link \033[91mFAILED \033[97m\nCould not automatically link package :'+
68
- err.stack +
69
- 'please follow the instructions to manually link the library : ' +
70
- '\033[4mhttps://github.com/RonRadtke/react-native-blob-util/wiki/Manually-Link-Package\n')
71
- }