@@ -23,6 +23,7 @@ Node.js and browser.
23
23
- [ High-Level API] ( #high-level-api )
24
24
- [ Low-Level API] ( #low-level-api )
25
25
- [ Settings] ( #settings )
26
+ - [ React Native] ( #react-native )
26
27
- [ Testing] ( #testing )
27
28
- [ Security issues] ( #security-issues )
28
29
- [ Feedback] ( #feedback )
@@ -124,7 +125,7 @@ interface UploadClient {
124
125
getSettings(): Settings
125
126
126
127
base(
127
- file : NodeFile | BrowserFile ,
128
+ file : Blob | File | Buffer | ReactNativeAsset ,
128
129
options : BaseOptions
129
130
): Promise <BaseResponse >
130
131
@@ -158,12 +159,12 @@ interface UploadClient {
158
159
): Promise <FileInfo >
159
160
160
161
uploadFile(
161
- data : NodeFile | BrowserFile | Url | Uuid ,
162
+ data : Blob | File | Buffer | ReactNativeAsset | Url | Uuid ,
162
163
options : FileFromOptions
163
164
): Promise <UploadcareFile >
164
165
165
166
uploadFileGroup(
166
- data : (NodeFile | BrowserFile )[] | Url [] | Uuid [],
167
+ data : (Blob | File | Buffer | ReactNativeAsset )[] | Url [] | Uuid [],
167
168
options : FileFromOptions & GroupFromOptions
168
169
): Promise <UploadcareGroup >
169
170
}
@@ -208,7 +209,7 @@ List of all available API methods:
208
209
209
210
``` typescript
210
211
base (
211
- file : NodeFile | BrowserFile ,
212
+ file : Blob | File | Buffer | ReactNativeAsset ,
212
213
options : BaseOptions
213
214
): Promise < BaseResponse >
214
215
```
@@ -245,7 +246,7 @@ multipartStart(
245
246
246
247
``` typescript
247
248
multipartUpload (
248
- part : Buffer | Blob ,
249
+ part : Buffer | Blob | File ,
249
250
url : MultipartPart ,
250
251
options : MultipartUploadOptions
251
252
): Promise < MultipartUploadResponse >
@@ -288,6 +289,7 @@ Defaults to `https://upload.uploadcare.com`
288
289
#### ` fileName: string `
289
290
290
291
You can specify an original filename.
292
+ It could useful when file input does not contain filename.
291
293
292
294
Defaults to ` original ` .
293
295
@@ -408,7 +410,7 @@ Defaults to `4`.
408
410
409
411
### ` contentType : string `
410
412
411
- This setting is needed for correct multipart uploads .
413
+ This option is useful when file input does not contain content type .
412
414
413
415
Defaults to ` application /octet -stream ` .
414
416
@@ -426,6 +428,64 @@ Non-string values will be converted to `string`. `undefined` values will be igno
426
428
427
429
See [docs][uc-file-metadata] and [REST API][uc-docs-metadata] for details.
428
430
431
+ ## React Native
432
+
433
+ ### Prepare
434
+
435
+ To be able to use ` @uploadcare /upload -client ` with React Native, you need to
436
+ install [react-native-url-polyfill][react-native-url-polyfill].
437
+
438
+ To prevent [ ` Error : Cannot create URL for blob ` ][react-native-url-polyfill-issue]
439
+ errors you need to configure your Android app schema to accept blobs -
440
+ have a look at this pull request for an example: [5985d7e][react-native-url-polyfill-example].
441
+
442
+ 1. Add the following code to the ` application ` section of your ` AndroidManifest .xml ` :
443
+
444
+ ` ` ` xml
445
+ <provider
446
+ android : name = " com.facebook.react.modules.blob.BlobProvider"
447
+ android : authorities = " @string/blob_provider_authority"
448
+ android : exported = " false"
449
+ />
450
+ ` ` `
451
+
452
+ 2. Add the following code to the ` android /app /src /main /res /values /strings .xml ` :
453
+
454
+ ` ` ` xml
455
+ <resources >
456
+ <string name = " app_name" >MY_REACT_NATIVE_APP_NAME </string >
457
+ <string name = " blob_provider_authority" >com .detox .blob </string >
458
+ </resources >
459
+ ` ` `
460
+
461
+ ### Usage
462
+
463
+ You can use ` ReactNativeAsset ` as an input to the ` @uploadcare /upload -client ` like this:
464
+
465
+ ` ` ` ts
466
+ type ReactNativeAsset = {
467
+ uri: string
468
+ type: string
469
+ name? : string
470
+ }
471
+ ` ` `
472
+
473
+ ` ` ` ts
474
+ const asset = { uri: ' URI_TO_FILE' , name: ' file.txt' , type: ' text/plain' }
475
+ uploadFile (asset , { publicKey: ' YOUR_PUBLIC_KEY' })
476
+ ```
477
+
478
+ Or ` Blob ` like this:
479
+
480
+ ``` ts
481
+ const uri = ' URI_TO_FILE'
482
+ const blob = await fetch (uri ).then ((res ) => res .blob ())
483
+ uploadFile (blob , {
484
+ publicKey: ' YOUR_PUBLIC_KEY' ,
485
+ fileName: ' file.txt' ,
486
+ contentType: ' text/plain'
487
+ })
488
+ ```
429
489
430
490
## Testing
431
491
490
550
[ uc-docs-upload-api ] : https://uploadcare.com/docs/api_reference/upload/?utm_source=github&utm_campaign=uploadcare-js-api-clients
491
551
[ uc-docs-metadata ] : https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/File-Metadata
492
552
[ uc-file-metadata ] : https://uploadcare.com/docs/file-metadata/
553
+ [ react-native-url-polyfill ] : https://github.com/charpeni/react-native-url-polyfill
554
+ [ react-native-url-polyfill-issue ] : https://github.com/charpeni/react-native-url-polyfill/issues/284
555
+ [ react-native-url-polyfill-example ] : https://github.com/charpeni/react-native-url-polyfill/commit/5985d7efc07b496b829883540d09c6f0be384387
0 commit comments