upload()
upload()
Section titled “upload()”Overload 1 of 2
Section titled “Overload 1 of 2”Use nhost.storage.upload to upload a file.
It’s possible to use File or FormData to upload a file. The File instance is only available in the browser while FormData with form-data works both in the browser and in NodeJS (server).
If no bucketId is specified the bucket default is used.
Parameters
Section titled “Parameters”params required StorageUploadFileParams
| Property | Type | Required | Notes |
|---|---|---|---|
| params.file | File | ✔️ | |
| params.bucketId | string | ||
| params.name | string | ||
| params.id | string | ||
| params.headers | Record<string, string> |
Examples
Section titled “Examples”Upload a file from a browser using File.
await nhost.storage.upload({ file })Upload a file from a browser using File to a specific Bucket.
await nhost.storage.upload({ file, bucketId: '<Bucket-ID>' })Upload a file from a server using FormData with form-data.
const fd = new FormData()fd.append('file', fs.createReadStream('./tests/assets/sample.pdf'))
await storage.upload({ formData: fd})Overload 2 of 2
Section titled “Overload 2 of 2”Parameters
Section titled “Parameters”params required StorageUploadFormDataParams
| Property | Type | Required | Notes |
|---|---|---|---|
| params.formData | FormData | FormData | ✔️ | |
| params.bucketId | string | ||
| params.headers | Record<string, string> |