Skip to content

Commit

Permalink
chore(upload-client): update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nd0ut committed Dec 29, 2022
1 parent 87efbb2 commit ed04c9c
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion packages/upload-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,36 @@ See [docs][uc-file-metadata] and [REST API][uc-docs-metadata] for details.
## React Native
### Prepare
To be able to use `@uploadcare/upload-client` with React Native, you need to
install [react-native-url-polyfill][react-native-url-polyfill].
To prevent [`Error: Cannot create URL for blob`][react-native-url-polyfill-issue]
errors you need to configure your Android app schema to accept blobs -
have a look at this pull request for an example: [5985d7e][react-native-url-polyfill-example].
1. Add the following code to the `application` section of your `AndroidManifest.xml`:
```xml
<provider
android:name="com.facebook.react.modules.blob.BlobProvider"
android:authorities="@string/blob_provider_authority"
android:exported="false"
/>
```
2. Add the following code to the `android/app/src/main/res/values/strings.xml`:
```xml
<resources>
<string name="app_name">MY_REACT_NATIVE_APP_NAME</string>
<string name="blob_provider_authority">com.detox.blob</string>
</resources>
```
### Usage
You can use `ReactNativeAsset` as an input to the `@uploadcare/upload-client` like this:
```ts
Expand All @@ -457,7 +480,11 @@ Or `Blob` like this:
```ts
const uri = 'URI_TO_FILE'
const blob = await fetch(uri).then((res) => res.blob())
uploadFile(blob, { publicKey: 'YOUR_PUBLIC_KEY' })
uploadFile(blob, {
publicKey: 'YOUR_PUBLIC_KEY',
fileName: 'file.txt',
contentType: 'text/plain'
})
```

## Testing
Expand Down

0 comments on commit ed04c9c

Please sign in to comment.