Skip to content

Commit 6ce36b8

Browse files
Ron RadtkeRon Radtke
Ron Radtke
authored and
Ron Radtke
committed
small fix and update for example app
1 parent c564d75 commit 6ce36b8

File tree

4 files changed

+122
-8
lines changed

4 files changed

+122
-8
lines changed

.eslintrc.js

+29-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
module.exports = {
22
root: true,
3+
extends: '@react-native-community',
34
rules: {
45
'prettier/prettier': 0,
56
"eqeqeq": 2,
67
"comma-dangle": 0,
7-
"curly": 0,
8+
curly: 0,
89
"no-console": 1,
910
"no-debugger": 1,
1011
"no-extra-semi": 2,
@@ -24,7 +25,32 @@ module.exports = {
2425
"requireReturnDescription": false
2526
}
2627
],
27-
"radix": 0
28+
"radix": 0,
29+
30+
"react/display-name": 2,
31+
"react/forbid-prop-types": 1,
32+
"react/jsx-boolean-value": 1,
33+
"react/jsx-closing-bracket-location": 1,
34+
"react/jsx-curly-spacing": 1,
35+
"react/jsx-indent-props": 0,
36+
"react/jsx-max-props-per-line": 0,
37+
"react/jsx-no-duplicate-props": 1,
38+
"react/jsx-no-literals": 0,
39+
"react/jsx-no-undef": 1,
40+
"react/jsx-sort-props": 0,
41+
"react/jsx-uses-react": 1,
42+
"react/jsx-uses-vars": 1,
43+
"react/jsx-wrap-multilines": 1,
44+
"react/no-danger": 1,
45+
"react/no-did-mount-set-state": 1,
46+
"react/no-did-update-set-state": 1,
47+
"react/no-direct-mutation-state": 1,
48+
"react/no-multi-comp": 1,
49+
"react/no-set-state": 0,
50+
"react/no-unknown-property": 1,
51+
"react/prop-types": 0,
52+
"react/react-in-jsx-scope": 0,
53+
"react/self-closing-comp": 1,
54+
"react/sort-comp": 1,
2855
},
29-
"parser": "babel-eslint"
3056
};

android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilReq.java

+2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ private boolean shouldTransformFile() {
124124
boolean timeout = false;
125125
ArrayList<String> redirects = new ArrayList<>();
126126
OkHttpClient client;
127+
boolean callbackfired;
127128

128129
public ReactNativeBlobUtilReq(ReadableMap options, String taskId, String method, String url, ReadableMap headers, String body, ReadableArray arrayBody, OkHttpClient client, final Callback callback) {
129130
this.method = method.toUpperCase(Locale.ROOT);
@@ -135,6 +136,7 @@ public ReactNativeBlobUtilReq(ReadableMap options, String taskId, String method,
135136
this.rawRequestBody = body;
136137
this.rawRequestBodyArray = arrayBody;
137138
this.client = client;
139+
this.callbackfired = false;
138140

139141
// If transformFile is specified, we first want to get the response back in memory so we can
140142
// encrypt it wholesale and at that point, write it into the file storage.
+54-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,56 @@
11
module.exports = {
2-
root: true,
3-
extends: '@react-native-community',
2+
root: true,
3+
extends: '@react-native-community',
4+
rules: {
5+
'prettier/prettier': 0,
6+
"eqeqeq": 2,
7+
"comma-dangle": 0,
8+
curly: 0,
9+
"no-console": 1,
10+
"no-debugger": 1,
11+
"no-extra-semi": 2,
12+
"no-extra-parens": 1,
13+
"no-extra-boolean-cast": 1,
14+
"no-cond-assign": 2,
15+
"no-irregular-whitespace": 2,
16+
"no-undef": 0,
17+
"no-unused-vars": 0,
18+
"semi": 2,
19+
"semi-spacing": 2,
20+
"valid-jsdoc": [
21+
1,
22+
{
23+
"requireReturn": false,
24+
"requireParamDescription": false,
25+
"requireReturnDescription": false
26+
}
27+
],
28+
"radix": 0,
29+
30+
"react/display-name": 2,
31+
"react/forbid-prop-types": 1,
32+
"react/jsx-boolean-value": 1,
33+
"react/jsx-closing-bracket-location": 1,
34+
"react/jsx-curly-spacing": 1,
35+
"react/jsx-indent-props": 0,
36+
"react/jsx-max-props-per-line": 0,
37+
"react/jsx-no-duplicate-props": 1,
38+
"react/jsx-no-literals": 0,
39+
"react/jsx-no-undef": 1,
40+
"react/jsx-sort-props": 0,
41+
"react/jsx-uses-react": 1,
42+
"react/jsx-uses-vars": 1,
43+
"react/jsx-wrap-multilines": 1,
44+
"react/no-danger": 1,
45+
"react/no-did-mount-set-state": 1,
46+
"react/no-did-update-set-state": 1,
47+
"react/no-direct-mutation-state": 1,
48+
"react/no-multi-comp": 1,
49+
"react/no-set-state": 0,
50+
"react/no-unknown-property": 1,
51+
"react/prop-types": 0,
52+
"react/react-in-jsx-scope": 0,
53+
"react/self-closing-comp": 1,
54+
"react/sort-comp": 1,
55+
},
456
};

examples/ReactNativeBlobUtil/App.js

+37-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
*/
88

99
import React, {useState} from 'react';
10-
import {SafeAreaView, StyleSheet, ScrollView, View, Text, StatusBar, TextInput, Button, Alert, Picker} from 'react-native';
10+
import {Alert, Button, SafeAreaView, ScrollView, StatusBar, StyleSheet, Text, TextInput, View} from 'react-native';
11+
import {Picker} from '@react-native-picker/picker';
1112

1213
import {Colors} from 'react-native/Libraries/NewAppScreen';
1314

@@ -316,6 +317,28 @@ const App: () => React$Node = () => {
316317
});
317318
};
318319

320+
// Android mediastorage store
321+
const androidmediastore = () => {
322+
ReactNativeBlobUtil.config({
323+
// add this option that makes response data to be stored as a file,
324+
// this is much more performant.
325+
fileCache: true,
326+
})
327+
.fetch('GET', 'https://upload.wikimedia.org/wikipedia/commons/c/c4/Change-5.png')
328+
.then((res) => {
329+
// the temp file path
330+
ReactNativeBlobUtil.MediaCollection.copyToMediaStore(
331+
{
332+
name: 'test.png',
333+
parentFolder: '',
334+
mimeType: 'image/png',
335+
},
336+
'Download',
337+
res.path(),
338+
).then((dest) => ReactNativeBlobUtil.android.actionViewIntent(dest, 'image/png'));
339+
});
340+
};
341+
319342
// uploadFileFromStorage
320343
const uploadFromStorageCall = () => {
321344
ReactNativeBlobUtil.fetch(
@@ -425,9 +448,19 @@ const App: () => React$Node = () => {
425448
// element with property `filename` will be transformed into `file` in form data
426449
{name: 'avatar', filename: 'avatar.png', data: 'Kentucky Fried Seth'},
427450
// custom content type
428-
{name: 'avatar-png', filename: 'avatar-png.png', type: 'image/png', data: 'whaddup my pickles'},
451+
{
452+
name: 'avatar-png',
453+
filename: 'avatar-png.png',
454+
type: 'image/png',
455+
data: 'whaddup my pickles',
456+
},
429457
// part file from storage
430-
{name: 'avatar-foo', filename: 'avatar-foo.png', type: 'image/foo', data: ReactNativeBlobUtil.wrap(ReactNativeBlobUtil.fs.dirs.DocumentDir + '\\ImageToUpload.jpg')},
458+
{
459+
name: 'avatar-foo',
460+
filename: 'avatar-foo.png',
461+
type: 'image/foo',
462+
data: ReactNativeBlobUtil.wrap(ReactNativeBlobUtil.fs.dirs.DocumentDir + '\\ImageToUpload.jpg'),
463+
},
431464
// elements without property `filename` will be sent as plain text
432465
{name: 'name', data: 'user'},
433466
{
@@ -644,6 +677,7 @@ const App: () => React$Node = () => {
644677
<Text style={styles.sectionTitle}>{'FetchBlobTest'}</Text>
645678
<View style={styles.sectionDescription} />
646679
<Button title="Attempt Fetch" color="#9a73ef" onPress={fetchCall} />
680+
<Button title="Attempt Android Media Storage" color="#9a73ef" onPress={androidmediastore} />
647681
<Button title="Upload File from Storage" color="#9a73ef" onPress={uploadFromStorageCall} />
648682
<Button title="Upload Text From Storage" color="#9a73ef" onPress={uploadTextFromCall} />
649683
<Button title="Multipart Call" color="#9a73ef" onPress={MultipartFileAndData} />

0 commit comments

Comments
 (0)