|
7 | 7 | */
|
8 | 8 |
|
9 | 9 | 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'; |
11 | 12 |
|
12 | 13 | import {Colors} from 'react-native/Libraries/NewAppScreen';
|
13 | 14 |
|
@@ -316,6 +317,28 @@ const App: () => React$Node = () => {
|
316 | 317 | });
|
317 | 318 | };
|
318 | 319 |
|
| 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 | + |
319 | 342 | // uploadFileFromStorage
|
320 | 343 | const uploadFromStorageCall = () => {
|
321 | 344 | ReactNativeBlobUtil.fetch(
|
@@ -425,9 +448,19 @@ const App: () => React$Node = () => {
|
425 | 448 | // element with property `filename` will be transformed into `file` in form data
|
426 | 449 | {name: 'avatar', filename: 'avatar.png', data: 'Kentucky Fried Seth'},
|
427 | 450 | // 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 | + }, |
429 | 457 | // 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 | + }, |
431 | 464 | // elements without property `filename` will be sent as plain text
|
432 | 465 | {name: 'name', data: 'user'},
|
433 | 466 | {
|
@@ -644,6 +677,7 @@ const App: () => React$Node = () => {
|
644 | 677 | <Text style={styles.sectionTitle}>{'FetchBlobTest'}</Text>
|
645 | 678 | <View style={styles.sectionDescription} />
|
646 | 679 | <Button title="Attempt Fetch" color="#9a73ef" onPress={fetchCall} />
|
| 680 | + <Button title="Attempt Android Media Storage" color="#9a73ef" onPress={androidmediastore} /> |
647 | 681 | <Button title="Upload File from Storage" color="#9a73ef" onPress={uploadFromStorageCall} />
|
648 | 682 | <Button title="Upload Text From Storage" color="#9a73ef" onPress={uploadTextFromCall} />
|
649 | 683 | <Button title="Multipart Call" color="#9a73ef" onPress={MultipartFileAndData} />
|
|
0 commit comments