@@ -360,7 +360,7 @@ const App: () => React$Node = () => {
360
360
} )
361
361
. fetch (
362
362
'POST' ,
363
- 'https://content.dropboxapi.com/2/files/upload ' ,
363
+ 'https://enb954aqyumba.x.pipedream.net ' ,
364
364
{
365
365
Authorization : "Bearer access-token..." ,
366
366
'Dropbox-API-Arg' : JSON . stringify ( {
@@ -381,6 +381,113 @@ const App: () => React$Node = () => {
381
381
} ) ;
382
382
}
383
383
384
+ // uploadFileFromStorage
385
+ const uploadFromStorageCall = ( ) => {
386
+ RNFetchBlob . fetch ( 'POST' , 'https://enb954aqyumba.x.pipedream.net' , {
387
+ Authorization : "Bearer access-token..." ,
388
+ 'Dropbox-API-Arg' : JSON . stringify ( {
389
+ path : '/img-from-react-native.png' ,
390
+ mode : 'add' ,
391
+ autorename : true ,
392
+ mute : false
393
+ } ) ,
394
+ 'Content-Type' : 'application/octet-stream' ,
395
+ // here's the body you're going to send, should be a BASE64 encoded string
396
+ // (you can use "base64"(refer to the library 'mathiasbynens/base64') APIs to make one).
397
+ // The data will be converted to "byte array"(say, blob) before request sent.
398
+ } , RNFetchBlob . wrap ( RNFetchBlob . fs . dirs . DocumentDir + '/temp1.txt' ) )
399
+ . then ( ( res ) => {
400
+ console . log ( res . text ( ) ) ;
401
+ } )
402
+ . catch ( ( err ) => {
403
+ // error handling ..
404
+ } )
405
+ }
406
+
407
+ // uploadTextFromStorage
408
+ const uploadTextFromCall = ( ) => {
409
+ RNFetchBlob . fetch ( 'POST' , 'https://enb954aqyumba.x.pipedream.net' , {
410
+ Authorization : "Bearer access-token..." ,
411
+ 'Dropbox-API-Arg' : JSON . stringify ( {
412
+ path : '/img-from-react-native.png' ,
413
+ mode : 'add' ,
414
+ autorename : true ,
415
+ mute : false
416
+ } ) ,
417
+ 'Content-Type' : 'application/octet-stream' ,
418
+ // here's the body you're going to send, should be a BASE64 encoded string
419
+ // (you can use "base64"(refer to the library 'mathiasbynens/base64') APIs to make one).
420
+ // The data will be converted to "byte array"(say, blob) before request sent.
421
+ } , "Waka Flacka Flame goes very well with Thomas the Tank Engine." )
422
+ . then ( ( res ) => {
423
+ console . log ( res . text ( ) ) ;
424
+ } )
425
+ . catch ( ( err ) => {
426
+ // error handling ..
427
+ } )
428
+ }
429
+
430
+ // MultipartFileAndData
431
+ const MultipartFileAndData = ( ) => {
432
+ RNFetchBlob . fetch ( 'POST' , 'https://enb954aqyumba.x.pipedream.net' , {
433
+ Authorization : "Bearer access-token..." ,
434
+ 'Dropbox-API-Arg' : JSON . stringify ( {
435
+ path : '/img-from-react-native.png' ,
436
+ mode : 'add' ,
437
+ autorename : true ,
438
+ mute : false
439
+ } ) ,
440
+ 'Content-Type' : 'application/octet-stream' ,
441
+ // here's the body you're going to send, should be a BASE64 encoded string
442
+ // (you can use "base64"(refer to the library 'mathiasbynens/base64') APIs to make one).
443
+ // The data will be converted to "byte array"(say, blob) before request sent.
444
+ } , "Waka Flacka Flame goes very well with Thomas the Tank Engine." )
445
+ . progress ( ( received , total ) => {
446
+ console . log ( 'progress' , received / total )
447
+ } )
448
+ . then ( ( res ) => {
449
+ console . log ( res . text ( ) ) ;
450
+ } )
451
+ . catch ( ( err ) => {
452
+ // error handling ..
453
+ } )
454
+ }
455
+
456
+ //
457
+ const MakeRequestWithProgress = ( ) => {
458
+ RNFetchBlob . config ( {
459
+ // add this option that makes response data to be stored as a file,
460
+ // this is much more performant.
461
+ Progress : { count : 10 , interval : 10 } ,
462
+ UploadProgress : { count : 10 , interval : 10 } ,
463
+ fileCache : true ,
464
+ } ) . fetch ( 'POST' , 'https://enb954aqyumba.x.pipedream.net' , {
465
+ Authorization : "Bearer access-token" ,
466
+ otherHeader : "foo" ,
467
+ 'Content-Type' : 'multipart/form-data' ,
468
+ } , [
469
+ // element with property `filename` will be transformed into `file` in form data
470
+ { name : 'avatar' , filename : 'avatar.png' , data : "Kentucky Fried Seth" } ,
471
+ // custom content type
472
+ { name : 'avatar-png' , filename : 'avatar-png.png' , type :'image/png' , data : "whaddup my pickles" } ,
473
+ // part file from storage
474
+ { name : 'avatar-foo' , filename : 'avatar-foo.png' , type :'image/foo' , data : RNFetchBlob . wrap ( RNFetchBlob . fs . dirs . DocumentDir + '/temp1.txt' ) } ,
475
+ // elements without property `filename` will be sent as plain text
476
+ { name : 'name' , data : 'user' } ,
477
+ { name : 'info' , data : JSON . stringify ( {
478
+
479
+ tel : '12345678'
480
+ } ) } ,
481
+ ] ) . progress ( ( received , total ) => {
482
+ console . log ( 'progress' , received / total )
483
+ } ) . then ( ( res ) => {
484
+ console . log ( res . text ( ) ) ;
485
+ } )
486
+ . catch ( ( err ) => {
487
+ // error handling ..
488
+ } )
489
+ }
490
+
384
491
// App ************************************************************************
385
492
return (
386
493
< >
@@ -796,6 +903,26 @@ const App: () => React$Node = () => {
796
903
color = "#9a73ef"
797
904
onPress = { fetchCall }
798
905
/>
906
+ < Button
907
+ title = "Attempt Storage Call Fetch"
908
+ color = "#9a73ef"
909
+ onPress = { uploadFromStorageCall }
910
+ />
911
+ < Button
912
+ title = "Upload Text From Call"
913
+ color = "#9a73ef"
914
+ onPress = { uploadTextFromCall }
915
+ />
916
+ < Button
917
+ title = "Multipart Call"
918
+ color = "#9a73ef"
919
+ onPress = { MultipartFileAndData }
920
+ />
921
+ < Button
922
+ title = "Progress Call"
923
+ color = "#9a73ef"
924
+ onPress = { MakeRequestWithProgress }
925
+ />
799
926
</ View >
800
927
</ View >
801
928
0 commit comments