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 533a1fc commit da0f877
Showing 1 changed file with 42 additions and 6 deletions.
48 changes: 42 additions & 6 deletions packages/upload-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Node.js and browser.
- [High-Level API](#high-level-api)
- [Low-Level API](#low-level-api)
- [Settings](#settings)
- [React Native](#react-native)
- [Testing](#testing)
- [Security issues](#security-issues)
- [Feedback](#feedback)
Expand Down Expand Up @@ -124,7 +125,7 @@ interface UploadClient {
getSettings(): Settings

base(
file: NodeFile | BrowserFile,
file: Blob | File | Buffer | ReactNativeAsset,
options: BaseOptions
): Promise<BaseResponse>

Expand Down Expand Up @@ -158,12 +159,12 @@ interface UploadClient {
): Promise<FileInfo>

uploadFile(
data: NodeFile | BrowserFile | Url | Uuid,
data: Blob | File | Buffer | ReactNativeAsset | Url | Uuid,
options: FileFromOptions
): Promise<UploadcareFile>

uploadFileGroup(
data: (NodeFile | BrowserFile)[] | Url[] | Uuid[],
data: (Blob | File | Buffer | ReactNativeAsset)[] | Url[] | Uuid[],
options: FileFromOptions & GroupFromOptions
): Promise<UploadcareGroup>
}
Expand Down Expand Up @@ -208,7 +209,7 @@ List of all available API methods:

```typescript
base(
file: NodeFile | BrowserFile,
file: Blob | File | Buffer | ReactNativeAsset,
options: BaseOptions
): Promise<BaseResponse>
```
Expand Down Expand Up @@ -245,7 +246,7 @@ multipartStart(

```typescript
multipartUpload(
part: Buffer | Blob,
part: Buffer | Blob | File,
url: MultipartPart,
options: MultipartUploadOptions
): Promise<MultipartUploadResponse>
Expand Down Expand Up @@ -288,6 +289,7 @@ Defaults to `https://upload.uploadcare.com`
#### `fileName: string`

You can specify an original filename.
It could useful when file input does not contain filename.

Defaults to `original`.

Expand Down Expand Up @@ -408,7 +410,7 @@ Defaults to `4`.
### `contentType: string`
This setting is needed for correct multipart uploads.
This option is useful when file input does not contain content type.
Defaults to `application/octet-stream`.
Expand All @@ -426,6 +428,37 @@ Non-string values will be converted to `string`. `undefined` values will be igno
See [docs][uc-file-metadata] and [REST API][uc-docs-metadata] for details.
## React Native
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].
You can use `ReactNativeAsset` as an input to the `@uploadcare/upload-client` like this:
```ts
type ReactNativeAsset = {
uri: string
type: string
name?: string
}
```
```ts
const asset = { uri: 'URI_TO_FILE', name: 'file.txt', type: 'text/plain' }
uploadFile(asset, { publicKey: 'YOUR_PUBLIC_KEY' })
```

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' })
```

## Testing

Expand Down Expand Up @@ -490,3 +523,6 @@ request at [[email protected]][uc-email-hello].
[uc-docs-upload-api]: https://uploadcare.com/docs/api_reference/upload/?utm_source=github&utm_campaign=uploadcare-js-api-clients
[uc-docs-metadata]: https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/File-Metadata
[uc-file-metadata]: https://uploadcare.com/docs/file-metadata/
[react-native-url-polyfill]: https://github.com/charpeni/react-native-url-polyfill
[react-native-url-polyfill-issue]: https://github.com/charpeni/react-native-url-polyfill/issues/284
[react-native-url-polyfill-example]: https://github.com/charpeni/react-native-url-polyfill/commit/5985d7efc07b496b829883540d09c6f0be384387

0 comments on commit da0f877

Please sign in to comment.