react-native-blob-util 0.13.17 → 0.14.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 +472 -407
- package/android/build.gradle +1 -0
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtil.java +85 -21
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilBody.java +14 -15
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilConfig.java +8 -6
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFS.java +92 -292
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilMediaCollection.java +299 -0
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilPackage.java +6 -2
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilReq.java +17 -21
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilStream.java +287 -0
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilUtils.java +57 -2
- package/android/src/main/java/com/ReactNativeBlobUtil/Response/ReactNativeBlobUtilFileResp.java +5 -0
- package/android/src/main/java/com/ReactNativeBlobUtil/Utils/FileDescription.java +19 -0
- package/android/src/main/java/com/ReactNativeBlobUtil/Utils/MimeType.java +70 -0
- package/fs.js +2 -1
- package/index.d.ts +107 -2
- package/index.js +2 -0
- package/ios/ReactNativeBlobUtil/ReactNativeBlobUtil.m +2 -1
- package/ios/ReactNativeBlobUtilFS.h +1 -0
- package/ios/ReactNativeBlobUtilFS.m +4 -0
- package/ios/ReactNativeBlobUtilReqBuilder.m +1 -0
- package/mediacollection.js +33 -0
- package/package.json +1 -1
- package/scripts/prelink.js +1 -1
- package/types.js +3 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
package com.ReactNativeBlobUtil;
|
|
2
|
+
|
|
3
|
+
import android.content.ContentResolver;
|
|
4
|
+
import android.content.ContentValues;
|
|
5
|
+
import android.content.Context;
|
|
6
|
+
import android.net.Uri;
|
|
7
|
+
import android.os.Build;
|
|
8
|
+
import android.os.Environment;
|
|
9
|
+
import android.os.ParcelFileDescriptor;
|
|
10
|
+
import android.provider.MediaStore;
|
|
11
|
+
import android.util.Base64;
|
|
12
|
+
|
|
13
|
+
import com.ReactNativeBlobUtil.Utils.FileDescription;
|
|
14
|
+
import com.facebook.react.bridge.Arguments;
|
|
15
|
+
import com.facebook.react.bridge.Promise;
|
|
16
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
17
|
+
import com.facebook.react.bridge.WritableArray;
|
|
18
|
+
|
|
19
|
+
import java.io.File;
|
|
20
|
+
import java.io.FileInputStream;
|
|
21
|
+
import java.io.FileOutputStream;
|
|
22
|
+
import java.io.IOException;
|
|
23
|
+
import java.io.InputStream;
|
|
24
|
+
import java.io.OutputStream;
|
|
25
|
+
|
|
26
|
+
public class ReactNativeBlobUtilMediaCollection {
|
|
27
|
+
|
|
28
|
+
public enum MediaType {
|
|
29
|
+
Audio,
|
|
30
|
+
Image,
|
|
31
|
+
Video,
|
|
32
|
+
Download
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private static Uri getMediaUri(MediaType mt) {
|
|
36
|
+
Uri res = null;
|
|
37
|
+
if (mt == MediaType.Audio) {
|
|
38
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
39
|
+
res = MediaStore.Audio.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
|
|
40
|
+
} else {
|
|
41
|
+
res = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
|
42
|
+
}
|
|
43
|
+
} else if (mt == MediaType.Video) {
|
|
44
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
45
|
+
res = MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
|
|
46
|
+
} else {
|
|
47
|
+
res = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
|
|
48
|
+
}
|
|
49
|
+
} else if (mt == MediaType.Image) {
|
|
50
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
51
|
+
res = MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
|
|
52
|
+
} else {
|
|
53
|
+
res = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
|
54
|
+
}
|
|
55
|
+
} else if (mt == MediaType.Download) {
|
|
56
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
57
|
+
res = MediaStore.Downloads.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return res;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private static String getRelativePath(MediaType mt, ReactApplicationContext ctx) {
|
|
65
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
66
|
+
if (mt == MediaType.Audio) return Environment.DIRECTORY_MUSIC;
|
|
67
|
+
if (mt == MediaType.Video) return Environment.DIRECTORY_MOVIES;
|
|
68
|
+
if (mt == MediaType.Image) return Environment.DIRECTORY_PICTURES;
|
|
69
|
+
if (mt == MediaType.Download) return Environment.DIRECTORY_DOWNLOADS;
|
|
70
|
+
return Environment.DIRECTORY_DOWNLOADS;
|
|
71
|
+
} else {
|
|
72
|
+
if (mt == MediaType.Audio) return ReactNativeBlobUtilFS.getExternalFilesDirPath(ctx, Environment.DIRECTORY_MUSIC);
|
|
73
|
+
if (mt == MediaType.Video) return ReactNativeBlobUtilFS.getExternalFilesDirPath(ctx, Environment.DIRECTORY_MOVIES);
|
|
74
|
+
if (mt == MediaType.Image) return ReactNativeBlobUtilFS.getExternalFilesDirPath(ctx, Environment.DIRECTORY_PICTURES);
|
|
75
|
+
if (mt == MediaType.Download) return ReactNativeBlobUtilFS.getExternalFilesDirPath(ctx, Environment.DIRECTORY_DOWNLOADS);
|
|
76
|
+
return ReactNativeBlobUtilFS.getExternalFilesDirPath(ctx, Environment.DIRECTORY_DOWNLOADS);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public static Uri createNewMediaFile(FileDescription file, MediaType mt, ReactApplicationContext ctx) {
|
|
81
|
+
// Add a specific media item.
|
|
82
|
+
Context appCtx = ReactNativeBlobUtil.RCTContext.getApplicationContext();
|
|
83
|
+
ContentResolver resolver = appCtx.getContentResolver();
|
|
84
|
+
|
|
85
|
+
ContentValues fileDetails = new ContentValues();
|
|
86
|
+
String relativePath = getRelativePath(mt, ctx);
|
|
87
|
+
String mimeType = file.mimeType;
|
|
88
|
+
|
|
89
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
90
|
+
fileDetails.put(MediaStore.MediaColumns.DATE_ADDED, System.currentTimeMillis() / 1000);
|
|
91
|
+
fileDetails.put(MediaStore.MediaColumns.DATE_MODIFIED, System.currentTimeMillis() / 1000);
|
|
92
|
+
fileDetails.put(MediaStore.MediaColumns.MIME_TYPE, mimeType);
|
|
93
|
+
fileDetails.put(MediaStore.MediaColumns.DISPLAY_NAME, file.name);
|
|
94
|
+
fileDetails.put(MediaStore.MediaColumns.RELATIVE_PATH, relativePath + '/' + file.partentFolder);
|
|
95
|
+
|
|
96
|
+
Uri mediauri = getMediaUri(mt);
|
|
97
|
+
|
|
98
|
+
// Keeps a handle to the new file's URI in case we need to modify it later.
|
|
99
|
+
return resolver.insert(mediauri, fileDetails);
|
|
100
|
+
} else {
|
|
101
|
+
File f = new File(relativePath + file.getFullPath());
|
|
102
|
+
if (true) {
|
|
103
|
+
if (!f.exists()) {
|
|
104
|
+
File parent = f.getParentFile();
|
|
105
|
+
if (parent != null && !parent.exists() && !parent.mkdirs()) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
if (f.createNewFile()) ;
|
|
110
|
+
{
|
|
111
|
+
return Uri.fromFile(f);
|
|
112
|
+
}
|
|
113
|
+
} catch (IOException ioException) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
} else {
|
|
118
|
+
return Uri.fromFile(f);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
public static boolean writeToMediaFile(Uri fileUri, String data, Promise promise) {
|
|
128
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
129
|
+
try {
|
|
130
|
+
Context appCtx = ReactNativeBlobUtil.RCTContext.getApplicationContext();
|
|
131
|
+
ContentResolver resolver = appCtx.getContentResolver();
|
|
132
|
+
|
|
133
|
+
// set pending doesn't work right now. We would have to requery for the item
|
|
134
|
+
//ContentValues contentValues = new ContentValues();
|
|
135
|
+
//contentValues.put(MediaStore.MediaColumns.IS_PENDING, 1);
|
|
136
|
+
//resolver.update(fileUri, contentValues, null, null);
|
|
137
|
+
|
|
138
|
+
// write data
|
|
139
|
+
OutputStream stream = null;
|
|
140
|
+
Uri uri = null;
|
|
141
|
+
|
|
142
|
+
try {
|
|
143
|
+
ParcelFileDescriptor descr;
|
|
144
|
+
try {
|
|
145
|
+
assert fileUri != null;
|
|
146
|
+
descr = appCtx.getContentResolver().openFileDescriptor(fileUri, "w");
|
|
147
|
+
assert descr != null;
|
|
148
|
+
String normalizedData = ReactNativeBlobUtilUtils.normalizePath(data);
|
|
149
|
+
File src = new File(normalizedData);
|
|
150
|
+
if (!src.exists()) {
|
|
151
|
+
promise.reject("ENOENT", "No such file ('" + normalizedData + "')");
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
byte[] buf = new byte[10240];
|
|
155
|
+
int read;
|
|
156
|
+
|
|
157
|
+
FileInputStream fin = new FileInputStream(src);
|
|
158
|
+
FileOutputStream out = new FileOutputStream(descr.getFileDescriptor());
|
|
159
|
+
|
|
160
|
+
while ((read = fin.read(buf)) > 0) {
|
|
161
|
+
out.write(buf, 0, read);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
fin.close();
|
|
165
|
+
out.close();
|
|
166
|
+
descr.close();
|
|
167
|
+
} catch (Exception e) {
|
|
168
|
+
e.printStackTrace();
|
|
169
|
+
promise.reject(new IOException("Failed to get output stream."));
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
//contentValues.clear();
|
|
174
|
+
//contentValues.put(MediaStore.Video.Media.IS_PENDING, 0);
|
|
175
|
+
//appCtx.getContentResolver().update(fileUri, contentValues, null, null);
|
|
176
|
+
stream = resolver.openOutputStream(fileUri);
|
|
177
|
+
if (stream == null) {
|
|
178
|
+
promise.reject(new IOException("Failed to get output stream."));
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
} catch (IOException e) {
|
|
182
|
+
// Don't leave an orphan entry in the MediaStore
|
|
183
|
+
resolver.delete(uri, null, null);
|
|
184
|
+
promise.reject(e);
|
|
185
|
+
return false;
|
|
186
|
+
} finally {
|
|
187
|
+
if (stream != null) {
|
|
188
|
+
stream.close();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// remove pending
|
|
193
|
+
//contentValues = new ContentValues();
|
|
194
|
+
//contentValues.put(MediaStore.MediaColumns.IS_PENDING, 0);
|
|
195
|
+
//resolver.update(fileUri, contentValues, null, null);
|
|
196
|
+
|
|
197
|
+
} catch (IOException e) {
|
|
198
|
+
promise.reject("ReactNativeBlobUtil.createMediaFile", "Cannot write to file, file might not exist");
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
return true;
|
|
202
|
+
} else {
|
|
203
|
+
return ReactNativeBlobUtilFS.writeFile(ReactNativeBlobUtilUtils.normalizePath(fileUri.toString()), ReactNativeBlobUtilConst.DATA_ENCODE_URI, data, false);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
public static void copyToInternal(Uri contenturi, String destpath, Promise promise) {
|
|
208
|
+
Context appCtx = ReactNativeBlobUtil.RCTContext.getApplicationContext();
|
|
209
|
+
ContentResolver resolver = appCtx.getContentResolver();
|
|
210
|
+
|
|
211
|
+
InputStream in = null;
|
|
212
|
+
OutputStream out = null;
|
|
213
|
+
File f = new File((destpath));
|
|
214
|
+
|
|
215
|
+
if (!f.exists()) {
|
|
216
|
+
try {
|
|
217
|
+
File parent = f.getParentFile();
|
|
218
|
+
if (parent != null && !parent.exists() && !parent.mkdirs()) {
|
|
219
|
+
promise.reject("ReactNativeBlobUtil.copyToInternal: Cannot create parent folders<'" + destpath);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
boolean result = f.createNewFile();
|
|
223
|
+
if (!result) {
|
|
224
|
+
promise.reject("ReactNativeBlobUtil.copyToInternal: Destination file at '" + destpath + "' already exists");
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
} catch (IOException ioException) {
|
|
228
|
+
promise.reject("ReactNativeBlobUtil.copyToInternal: Could not create file: " + ioException.getLocalizedMessage());
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
try {
|
|
233
|
+
in = resolver.openInputStream(contenturi);
|
|
234
|
+
out = new FileOutputStream(destpath);
|
|
235
|
+
|
|
236
|
+
byte[] buf = new byte[10240];
|
|
237
|
+
int len;
|
|
238
|
+
while ((len = in.read(buf)) > 0) {
|
|
239
|
+
out.write(buf, 0, len);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
} catch (IOException e) {
|
|
243
|
+
promise.reject("ReactNativeBlobUtil.copyToInternal: Could not write data: " + e.getLocalizedMessage());
|
|
244
|
+
} finally {
|
|
245
|
+
if (in != null) {
|
|
246
|
+
try {
|
|
247
|
+
in.close();
|
|
248
|
+
} catch (IOException ioException) {
|
|
249
|
+
ioException.printStackTrace();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (out != null) {
|
|
253
|
+
try {
|
|
254
|
+
out.close();
|
|
255
|
+
} catch (IOException ioException) {
|
|
256
|
+
ioException.printStackTrace();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
promise.resolve("");
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
public static void getBlob(Uri contentUri, String encoding, Promise promise) {
|
|
265
|
+
Context appCtx = ReactNativeBlobUtil.RCTContext.getApplicationContext();
|
|
266
|
+
ContentResolver resolver = appCtx.getContentResolver();
|
|
267
|
+
try {
|
|
268
|
+
InputStream in = resolver.openInputStream(contentUri);
|
|
269
|
+
int length = in.available();
|
|
270
|
+
|
|
271
|
+
byte[] bytes = new byte[length];
|
|
272
|
+
int bytesRead = in.read(bytes);
|
|
273
|
+
in.close();
|
|
274
|
+
|
|
275
|
+
if (bytesRead < length) {
|
|
276
|
+
promise.reject("EUNSPECIFIED", "Read only " + bytesRead + " bytes of " + length);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
switch (encoding.toLowerCase()) {
|
|
281
|
+
case "base64":
|
|
282
|
+
promise.resolve(Base64.encodeToString(bytes, Base64.NO_WRAP));
|
|
283
|
+
break;
|
|
284
|
+
case "ascii":
|
|
285
|
+
WritableArray asciiResult = Arguments.createArray();
|
|
286
|
+
for (byte b : bytes) {
|
|
287
|
+
asciiResult.pushInt(b);
|
|
288
|
+
}
|
|
289
|
+
promise.resolve(asciiResult);
|
|
290
|
+
break;
|
|
291
|
+
default: // covers utf-8
|
|
292
|
+
promise.resolve(new String(bytes));
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
} catch (IOException ioException) {
|
|
296
|
+
ioException.printStackTrace();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
package com.ReactNativeBlobUtil;
|
|
2
2
|
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
3
5
|
import com.facebook.react.ReactPackage;
|
|
4
6
|
import com.facebook.react.bridge.JavaScriptModule;
|
|
5
7
|
import com.facebook.react.bridge.NativeModule;
|
|
@@ -13,8 +15,9 @@ import java.util.List;
|
|
|
13
15
|
|
|
14
16
|
public class ReactNativeBlobUtilPackage implements ReactPackage {
|
|
15
17
|
|
|
18
|
+
@NonNull
|
|
16
19
|
@Override
|
|
17
|
-
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
20
|
+
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
|
18
21
|
List<NativeModule> modules = new ArrayList<>();
|
|
19
22
|
modules.add(new ReactNativeBlobUtil(reactContext));
|
|
20
23
|
return modules;
|
|
@@ -24,8 +27,9 @@ public class ReactNativeBlobUtilPackage implements ReactPackage {
|
|
|
24
27
|
return Collections.emptyList();
|
|
25
28
|
}
|
|
26
29
|
|
|
30
|
+
@NonNull
|
|
27
31
|
@Override
|
|
28
|
-
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
32
|
+
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
|
|
29
33
|
return Collections.emptyList();
|
|
30
34
|
}
|
|
31
35
|
|
|
@@ -30,33 +30,27 @@ import com.facebook.react.bridge.WritableArray;
|
|
|
30
30
|
import com.facebook.react.bridge.WritableMap;
|
|
31
31
|
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
32
32
|
|
|
33
|
-
import javax.net.ssl.TrustManagerFactory;
|
|
34
|
-
import javax.net.ssl.TrustManager;
|
|
35
|
-
import javax.net.ssl.X509TrustManager;
|
|
36
|
-
import javax.net.ssl.SSLContext;
|
|
37
|
-
|
|
38
33
|
import java.io.File;
|
|
39
34
|
import java.io.FileOutputStream;
|
|
40
35
|
import java.io.IOException;
|
|
41
36
|
import java.io.InputStream;
|
|
42
37
|
import java.net.MalformedURLException;
|
|
38
|
+
import java.net.Proxy;
|
|
43
39
|
import java.net.SocketException;
|
|
44
40
|
import java.net.SocketTimeoutException;
|
|
45
41
|
import java.net.URL;
|
|
46
|
-
import java.net.Proxy;
|
|
47
42
|
import java.nio.ByteBuffer;
|
|
48
43
|
import java.nio.charset.CharacterCodingException;
|
|
49
44
|
import java.nio.charset.Charset;
|
|
50
45
|
import java.nio.charset.CharsetDecoder;
|
|
51
|
-
import java.security.KeyStore;
|
|
52
46
|
import java.util.ArrayList;
|
|
53
|
-
import java.util.Arrays;
|
|
54
|
-
import java.util.List;
|
|
55
47
|
import java.util.HashMap;
|
|
56
48
|
|
|
49
|
+
import java.util.List;
|
|
50
|
+
import java.util.Locale;
|
|
57
51
|
import java.util.concurrent.TimeUnit;
|
|
58
52
|
|
|
59
|
-
import javax.net.ssl.
|
|
53
|
+
import javax.net.ssl.SSLContext;
|
|
60
54
|
|
|
61
55
|
import okhttp3.Call;
|
|
62
56
|
import okhttp3.ConnectionPool;
|
|
@@ -120,7 +114,7 @@ public class ReactNativeBlobUtilReq extends BroadcastReceiver implements Runnabl
|
|
|
120
114
|
OkHttpClient client;
|
|
121
115
|
|
|
122
116
|
public ReactNativeBlobUtilReq(ReadableMap options, String taskId, String method, String url, ReadableMap headers, String body, ReadableArray arrayBody, OkHttpClient client, final Callback callback) {
|
|
123
|
-
this.method = method.toUpperCase();
|
|
117
|
+
this.method = method.toUpperCase(Locale.ROOT);
|
|
124
118
|
this.options = new ReactNativeBlobUtilConfig(options);
|
|
125
119
|
this.taskId = taskId;
|
|
126
120
|
this.url = url;
|
|
@@ -196,7 +190,7 @@ public class ReactNativeBlobUtilReq extends BroadcastReceiver implements Runnabl
|
|
|
196
190
|
req.addRequestHeader(key, headers.getString(key));
|
|
197
191
|
}
|
|
198
192
|
// Attempt to add cookie, if it exists
|
|
199
|
-
URL urlObj
|
|
193
|
+
URL urlObj;
|
|
200
194
|
try {
|
|
201
195
|
urlObj = new URL(url);
|
|
202
196
|
String baseUrl = urlObj.getProtocol() + "://" + urlObj.getHost();
|
|
@@ -311,14 +305,14 @@ public class ReactNativeBlobUtilReq extends BroadcastReceiver implements Runnabl
|
|
|
311
305
|
else if (value.equalsIgnoreCase("utf8"))
|
|
312
306
|
responseFormat = ResponseFormat.UTF8;
|
|
313
307
|
} else {
|
|
314
|
-
builder.header(key.toLowerCase(), value);
|
|
315
|
-
mheaders.put(key.toLowerCase(), value);
|
|
308
|
+
builder.header(key.toLowerCase(Locale.ROOT), value);
|
|
309
|
+
mheaders.put(key.toLowerCase(Locale.ROOT), value);
|
|
316
310
|
}
|
|
317
311
|
}
|
|
318
312
|
}
|
|
319
313
|
|
|
320
314
|
if (method.equalsIgnoreCase("post") || method.equalsIgnoreCase("put") || method.equalsIgnoreCase("patch")) {
|
|
321
|
-
String cType = getHeaderIgnoreCases(mheaders, "Content-Type").toLowerCase();
|
|
315
|
+
String cType = getHeaderIgnoreCases(mheaders, "Content-Type").toLowerCase(Locale.ROOT);
|
|
322
316
|
|
|
323
317
|
if (rawRequestBodyArray != null) {
|
|
324
318
|
requestType = RequestType.Form;
|
|
@@ -332,7 +326,7 @@ public class ReactNativeBlobUtilReq extends BroadcastReceiver implements Runnabl
|
|
|
332
326
|
if (rawRequestBody.startsWith(ReactNativeBlobUtilConst.FILE_PREFIX)
|
|
333
327
|
|| rawRequestBody.startsWith(ReactNativeBlobUtilConst.CONTENT_PREFIX)) {
|
|
334
328
|
requestType = RequestType.SingleFile;
|
|
335
|
-
} else if (cType.toLowerCase().contains(";base64") || cType.toLowerCase().startsWith("application/octet")) {
|
|
329
|
+
} else if (cType.toLowerCase(Locale.ROOT).contains(";base64") || cType.toLowerCase(Locale.ROOT).startsWith("application/octet")) {
|
|
336
330
|
cType = cType.replace(";base64", "").replace(";BASE64", "");
|
|
337
331
|
if (mheaders.containsKey("content-type"))
|
|
338
332
|
mheaders.put("content-type", cType);
|
|
@@ -388,14 +382,16 @@ public class ReactNativeBlobUtilReq extends BroadcastReceiver implements Runnabl
|
|
|
388
382
|
// #156 fix cookie issue
|
|
389
383
|
final Request req = builder.build();
|
|
390
384
|
clientBuilder.addNetworkInterceptor(new Interceptor() {
|
|
385
|
+
@NonNull
|
|
391
386
|
@Override
|
|
392
|
-
public Response intercept(Chain chain) throws IOException {
|
|
387
|
+
public Response intercept(@NonNull Chain chain) throws IOException {
|
|
393
388
|
redirects.add(chain.request().url().toString());
|
|
394
389
|
return chain.proceed(chain.request());
|
|
395
390
|
}
|
|
396
391
|
});
|
|
397
392
|
// Add request interceptor for upload progress event
|
|
398
393
|
clientBuilder.addInterceptor(new Interceptor() {
|
|
394
|
+
@NonNull
|
|
399
395
|
@Override
|
|
400
396
|
public Response intercept(@NonNull Chain chain) throws IOException {
|
|
401
397
|
Response originalResponse = null;
|
|
@@ -467,7 +463,7 @@ public class ReactNativeBlobUtilReq extends BroadcastReceiver implements Runnabl
|
|
|
467
463
|
call.enqueue(new okhttp3.Callback() {
|
|
468
464
|
|
|
469
465
|
@Override
|
|
470
|
-
public void onFailure(@NonNull Call call, IOException e) {
|
|
466
|
+
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
|
471
467
|
cancelTask(taskId);
|
|
472
468
|
if (respInfo == null) {
|
|
473
469
|
respInfo = Arguments.createMap();
|
|
@@ -718,7 +714,7 @@ public class ReactNativeBlobUtilReq extends BroadcastReceiver implements Runnabl
|
|
|
718
714
|
boolean isCustomBinary = false;
|
|
719
715
|
if (options.binaryContentTypes != null) {
|
|
720
716
|
for (int i = 0; i < options.binaryContentTypes.size(); i++) {
|
|
721
|
-
if (ctype.toLowerCase().contains(options.binaryContentTypes.getString(i).toLowerCase())) {
|
|
717
|
+
if (ctype.toLowerCase(Locale.ROOT).contains(options.binaryContentTypes.getString(i).toLowerCase(Locale.ROOT))) {
|
|
722
718
|
isCustomBinary = true;
|
|
723
719
|
break;
|
|
724
720
|
}
|
|
@@ -730,13 +726,13 @@ public class ReactNativeBlobUtilReq extends BroadcastReceiver implements Runnabl
|
|
|
730
726
|
private String getHeaderIgnoreCases(Headers headers, String field) {
|
|
731
727
|
String val = headers.get(field);
|
|
732
728
|
if (val != null) return val;
|
|
733
|
-
return headers.get(field.toLowerCase()) == null ? "" : headers.get(field.toLowerCase());
|
|
729
|
+
return headers.get(field.toLowerCase(Locale.ROOT)) == null ? "" : headers.get(field.toLowerCase(Locale.ROOT));
|
|
734
730
|
}
|
|
735
731
|
|
|
736
732
|
private String getHeaderIgnoreCases(HashMap<String, String> headers, String field) {
|
|
737
733
|
String val = headers.get(field);
|
|
738
734
|
if (val != null) return val;
|
|
739
|
-
String lowerCasedValue = headers.get(field.toLowerCase());
|
|
735
|
+
String lowerCasedValue = headers.get(field.toLowerCase(Locale.ROOT));
|
|
740
736
|
return lowerCasedValue == null ? "" : lowerCasedValue;
|
|
741
737
|
}
|
|
742
738
|
|