react-native-blob-util 0.13.14 → 0.13.18
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 +6 -1
- package/android/build.gradle +48 -42
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtil.java +12 -20
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFS.java +3 -6
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilReq.java +12 -2
- package/fetch.js +1 -1
- package/index.d.ts +16 -2
- package/ios/ReactNativeBlobUtilReqBuilder.m +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -81,6 +81,11 @@ After `0.10.3` you can install this package directly from Github
|
|
|
81
81
|
# replace <branch_name> with any one of the branches
|
|
82
82
|
npm install --save github:RonRadtke/react-native-blob-util#<branch_name>
|
|
83
83
|
```
|
|
84
|
+
**Okhttp**
|
|
85
|
+
|
|
86
|
+
For using the library okhttp3 is required. It's in general included in react-native.
|
|
87
|
+
The library uses the okhttp version shipped with react-native or used by your app.
|
|
88
|
+
For very old devices android devices okhttp 3.12 can be used.
|
|
84
89
|
|
|
85
90
|
**Manually Link Native Modules**
|
|
86
91
|
|
|
@@ -646,7 +651,7 @@ In `v0.5.0` we've added `writeStream` and `readStream`, which allows your app r
|
|
|
646
651
|
|
|
647
652
|
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))
|
|
648
653
|
|
|
649
|
-
> The file stream event has a default throttle(10ms) and buffer size which preventing it cause too much overhead to main thread,
|
|
654
|
+
> The file stream event has a default throttle(10ms) and buffer size which preventing it cause too much overhead to main thread, you can also [tweak these values](#user-content-performance-tips).
|
|
650
655
|
|
|
651
656
|
```js
|
|
652
657
|
let data = ''
|
package/android/build.gradle
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
apply plugin: 'com.android.library'
|
|
2
|
-
apply plugin: 'maven'
|
|
2
|
+
apply plugin: 'maven-publish'
|
|
3
3
|
|
|
4
4
|
def safeExtGet(prop, fallback) {
|
|
5
5
|
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
@@ -50,53 +50,31 @@ android {
|
|
|
50
50
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
+
lintOptions {
|
|
54
|
+
abortOnError false
|
|
55
|
+
}
|
|
53
56
|
productFlavors {
|
|
54
57
|
}
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
dependencies {
|
|
58
61
|
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
|
|
59
|
-
implementation 'com.squareup.okhttp3:okhttp:3.12.+'
|
|
60
|
-
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.+'
|
|
61
|
-
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.12.+'
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
name packageJson.title
|
|
69
|
-
artifactId packageJson.name
|
|
70
|
-
version = packageJson.version
|
|
71
|
-
group = "com.ReactNativeBlobUtil"
|
|
72
|
-
description packageJson.description
|
|
73
|
-
url packageJson.repository.baseUrl
|
|
74
|
-
|
|
75
|
-
licenses {
|
|
76
|
-
license {
|
|
77
|
-
name packageJson.license
|
|
78
|
-
url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
|
|
79
|
-
distribution 'repo'
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
developers {
|
|
84
|
-
developer {
|
|
85
|
-
id packageJson.author.username
|
|
86
|
-
name packageJson.author.name
|
|
87
|
-
}
|
|
88
|
-
}
|
|
64
|
+
afterEvaluate { project ->
|
|
65
|
+
// do this only when building this lib alone as a root project
|
|
66
|
+
if (project != rootProject) {
|
|
67
|
+
return
|
|
89
68
|
}
|
|
90
|
-
}
|
|
91
69
|
|
|
92
|
-
afterEvaluate { project ->
|
|
93
70
|
// some Gradle build hooks ref:
|
|
94
71
|
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
|
|
95
72
|
task androidJavadoc(type: Javadoc) {
|
|
96
73
|
source = android.sourceSets.main.java.srcDirs
|
|
97
|
-
classpath += files(android.
|
|
98
|
-
classpath += files(
|
|
99
|
-
|
|
74
|
+
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
|
|
75
|
+
classpath += files(android.libraryVariants.collect { variant ->
|
|
76
|
+
variant.javaCompileProvider.get().classpath.files
|
|
77
|
+
})
|
|
100
78
|
}
|
|
101
79
|
|
|
102
80
|
task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
|
|
@@ -106,8 +84,7 @@ afterEvaluate { project ->
|
|
|
106
84
|
|
|
107
85
|
task androidSourcesJar(type: Jar) {
|
|
108
86
|
classifier = 'sources'
|
|
109
|
-
from android.sourceSets.main.java.
|
|
110
|
-
include '**/*.java'
|
|
87
|
+
from android.sourceSets.main.java.sourceFiles
|
|
111
88
|
}
|
|
112
89
|
|
|
113
90
|
android.libraryVariants.all { variant ->
|
|
@@ -124,12 +101,41 @@ afterEvaluate { project ->
|
|
|
124
101
|
archives androidJavadocJar
|
|
125
102
|
}
|
|
126
103
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
104
|
+
publishing {
|
|
105
|
+
publications {
|
|
106
|
+
mavenJava(MavenPublication) {
|
|
107
|
+
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)
|
|
108
|
+
|
|
109
|
+
artifactId packageJson.name
|
|
110
|
+
groupId = "com.ReactNativeBlobUtil"
|
|
111
|
+
version = packageJson.version
|
|
112
|
+
|
|
113
|
+
pom {
|
|
114
|
+
name = packageJson.title
|
|
115
|
+
description = packageJson.description
|
|
116
|
+
url = packageJson.repository.baseUrl
|
|
117
|
+
|
|
118
|
+
licenses {
|
|
119
|
+
license {
|
|
120
|
+
name = packageJson.license
|
|
121
|
+
url = packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
|
|
122
|
+
distribution = 'repo'
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
developers {
|
|
127
|
+
developer {
|
|
128
|
+
id = packageJson.author.username
|
|
129
|
+
name = packageJson.author.name
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
repositories {
|
|
136
|
+
maven {
|
|
137
|
+
url = "file://${projectDir}/../android/maven"
|
|
138
|
+
}
|
|
133
139
|
}
|
|
134
140
|
}
|
|
135
141
|
}
|
|
@@ -118,37 +118,29 @@ public class ReactNativeBlobUtil extends ReactContextBaseJavaModule {
|
|
|
118
118
|
this.getReactApplicationContext().getPackageName() + ".provider", new File(path));
|
|
119
119
|
|
|
120
120
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
121
|
-
if (Build.VERSION.SDK_INT >=
|
|
121
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
122
122
|
// Create the intent with data and type
|
|
123
123
|
intent.setDataAndType(uriForFile, mime);
|
|
124
|
-
if (chooserTitle != null) {
|
|
125
|
-
intent = Intent.createChooser(intent, chooserTitle);
|
|
126
|
-
}
|
|
127
124
|
|
|
128
125
|
// Set flag to give temporary permission to external app to use FileProvider
|
|
129
126
|
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
130
127
|
// All the activity to be opened outside of an activity
|
|
131
128
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
132
|
-
|
|
133
|
-
// Validate that the device can open the file
|
|
134
|
-
PackageManager pm = getCurrentActivity().getPackageManager();
|
|
135
|
-
if (intent.resolveActivity(pm) != null) {
|
|
136
|
-
this.getReactApplicationContext().startActivity(intent);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
129
|
} else {
|
|
140
130
|
intent.setDataAndType(Uri.parse("file://" + path), mime).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
141
|
-
|
|
142
|
-
intent = Intent.createChooser(intent, chooserTitle);
|
|
143
|
-
}
|
|
131
|
+
}
|
|
144
132
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
promise.resolve(true);
|
|
148
|
-
} catch (ActivityNotFoundException ex) {
|
|
149
|
-
promise.reject("ENOAPP", "No app installed for " + mime);
|
|
150
|
-
}
|
|
133
|
+
if (chooserTitle != null) {
|
|
134
|
+
intent = Intent.createChooser(intent, chooserTitle);
|
|
151
135
|
}
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
this.getReactApplicationContext().startActivity(intent);
|
|
139
|
+
promise.resolve(true);
|
|
140
|
+
} catch (ActivityNotFoundException ex) {
|
|
141
|
+
promise.reject("ENOAPP", "No app installed for " + mime);
|
|
142
|
+
}
|
|
143
|
+
|
|
152
144
|
ActionViewVisible = true;
|
|
153
145
|
|
|
154
146
|
final LifecycleEventListener listener = new LifecycleEventListener() {
|
|
@@ -57,7 +57,7 @@ class ReactNativeBlobUtilFS {
|
|
|
57
57
|
|
|
58
58
|
if (!f.exists()) {
|
|
59
59
|
if (dir != null && !dir.exists()) {
|
|
60
|
-
if (!dir.mkdirs()) {
|
|
60
|
+
if (!dir.mkdirs() && !dir.exists()) {
|
|
61
61
|
promise.reject("EUNSPECIFIED", "Failed to create parent directory of '" + path + "'");
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
@@ -129,7 +129,7 @@ class ReactNativeBlobUtilFS {
|
|
|
129
129
|
|
|
130
130
|
if (!f.exists()) {
|
|
131
131
|
if (dir != null && !dir.exists()) {
|
|
132
|
-
if (!dir.mkdirs()) {
|
|
132
|
+
if (!dir.mkdirs() && !dir.exists()) {
|
|
133
133
|
promise.reject("ENOTDIR", "Failed to create parent directory of '" + path + "'");
|
|
134
134
|
return;
|
|
135
135
|
}
|
|
@@ -445,7 +445,7 @@ class ReactNativeBlobUtilFS {
|
|
|
445
445
|
|
|
446
446
|
if (!dest.exists()) {
|
|
447
447
|
if (dir != null && !dir.exists()) {
|
|
448
|
-
if (!dir.mkdirs()) {
|
|
448
|
+
if (!dir.mkdirs() && !dir.exists()) {
|
|
449
449
|
callback.invoke("ENOTDIR", "Failed to create parent directory of '" + path + "'");
|
|
450
450
|
return;
|
|
451
451
|
}
|
|
@@ -1185,9 +1185,6 @@ class ReactNativeBlobUtilFS {
|
|
|
1185
1185
|
return null;
|
|
1186
1186
|
if (!path.matches("\\w+\\:.*"))
|
|
1187
1187
|
return path;
|
|
1188
|
-
if (path.startsWith("file://")) {
|
|
1189
|
-
return path.replace("file://", "");
|
|
1190
|
-
}
|
|
1191
1188
|
|
|
1192
1189
|
Uri uri = Uri.parse(path);
|
|
1193
1190
|
if (path.startsWith(ReactNativeBlobUtilConst.FILE_PREFIX_BUNDLE_ASSET)) {
|
|
@@ -398,8 +398,9 @@ public class ReactNativeBlobUtilReq extends BroadcastReceiver implements Runnabl
|
|
|
398
398
|
clientBuilder.addInterceptor(new Interceptor() {
|
|
399
399
|
@Override
|
|
400
400
|
public Response intercept(@NonNull Chain chain) throws IOException {
|
|
401
|
+
Response originalResponse = null;
|
|
401
402
|
try {
|
|
402
|
-
|
|
403
|
+
originalResponse = chain.proceed(req);
|
|
403
404
|
ResponseBody extended;
|
|
404
405
|
switch (responseType) {
|
|
405
406
|
case KeepInMemory:
|
|
@@ -428,12 +429,21 @@ public class ReactNativeBlobUtilReq extends BroadcastReceiver implements Runnabl
|
|
|
428
429
|
return originalResponse.newBuilder().body(extended).build();
|
|
429
430
|
} catch (SocketException e) {
|
|
430
431
|
timeout = true;
|
|
432
|
+
if (originalResponse != null) {
|
|
433
|
+
originalResponse.close();
|
|
434
|
+
}
|
|
431
435
|
} catch (SocketTimeoutException e) {
|
|
432
436
|
timeout = true;
|
|
437
|
+
if (originalResponse != null) {
|
|
438
|
+
originalResponse.close();
|
|
439
|
+
}
|
|
433
440
|
//ReactNativeBlobUtilUtils.emitWarningEvent("ReactNativeBlobUtil error when sending request : " + e.getLocalizedMessage());
|
|
434
441
|
} catch (Exception ex) {
|
|
435
|
-
|
|
442
|
+
if (originalResponse != null) {
|
|
443
|
+
originalResponse.close();
|
|
444
|
+
}
|
|
436
445
|
}
|
|
446
|
+
|
|
437
447
|
return chain.proceed(chain.request());
|
|
438
448
|
}
|
|
439
449
|
});
|
package/fetch.js
CHANGED
|
@@ -259,7 +259,7 @@ export function fetch(...args: any): Promise {
|
|
|
259
259
|
if (options.path || options.fileCache || options.addAndroidDownloads
|
|
260
260
|
|| options.key || options.auto && respInfo.respType === 'blob') {
|
|
261
261
|
if (options.session)
|
|
262
|
-
session(options.session).add(data);
|
|
262
|
+
fs.session(options.session).add(data);
|
|
263
263
|
}
|
|
264
264
|
respInfo.rnfbEncode = rawType;
|
|
265
265
|
resolve(new FetchBlobResponse(taskId, respInfo, data));
|
package/index.d.ts
CHANGED
|
@@ -392,9 +392,23 @@ export interface FS {
|
|
|
392
392
|
|
|
393
393
|
slice(src: string, dest: string, start: number, end: number): Promise<void>;
|
|
394
394
|
asset(path: string): string;
|
|
395
|
-
df(): Promise<
|
|
395
|
+
df(): Promise<RNFetchBlobDf>;
|
|
396
396
|
}
|
|
397
397
|
|
|
398
|
+
export interface RNFetchBlobDfIOS {
|
|
399
|
+
free?: number;
|
|
400
|
+
total?: number;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
export interface RNFetchBlobDfAndroid {
|
|
404
|
+
external_free?: string;
|
|
405
|
+
external_total?: string;
|
|
406
|
+
internal_free?: string;
|
|
407
|
+
internal_total?: string;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export type RNFetchBlobDf = RNFetchBlobDfIOS & RNFetchBlobDfAndroid;
|
|
411
|
+
|
|
398
412
|
export interface Dirs {
|
|
399
413
|
DocumentDir: string;
|
|
400
414
|
CacheDir: string;
|
|
@@ -509,7 +523,7 @@ export interface AndroidApi {
|
|
|
509
523
|
* @param mime Basically system will open an app according to this MIME type.
|
|
510
524
|
* @param chooserTitle title for chooser, if not set the chooser won't be displayed (see [Android docs](https://developer.android.com/reference/android/content/Intent.html#createChooser(android.content.Intent,%20java.lang.CharSequence)))
|
|
511
525
|
*/
|
|
512
|
-
actionViewIntent(path: string, mime: string, chooserTitle?: string): Promise<
|
|
526
|
+
actionViewIntent(path: string, mime: string, chooserTitle?: string): Promise<boolean | null>;
|
|
513
527
|
|
|
514
528
|
/**
|
|
515
529
|
*
|
|
@@ -115,6 +115,7 @@
|
|
|
115
115
|
if([body hasPrefix:FILE_PREFIX]) {
|
|
116
116
|
__block NSString * orgPath = [body substringFromIndex:[FILE_PREFIX length]];
|
|
117
117
|
orgPath = [ReactNativeBlobUtilFS getPathOfAsset:orgPath];
|
|
118
|
+
orgPath = [[NSURL URLWithString:orgPath] path];
|
|
118
119
|
if([orgPath hasPrefix:AL_PREFIX])
|
|
119
120
|
{
|
|
120
121
|
|
package/package.json
CHANGED