upload()

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


params required StorageUploadFileParams

PropertyTypeRequiredNotes
params.fileFile✔️
params.bucketIdstring
params.namestring
params.idstring
params.headersRecord<string, string>

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

Parameters


params required StorageUploadFormDataParams

PropertyTypeRequiredNotes
params.formDataFormData | FormData✔️
params.bucketIdstring
params.headersRecord<string, string>