Docs : SDK : uploadFile
uploadFile lets you upload files to a database. The file gets attached to an item, so you must create an item first via insertItem to upload a file. This API will return a promise that gets resolved once the file has been durably stored.
userbase.uploadFile({
databaseName: 'example-database-name',
itemId: 'example-id',
file: new File(['example'], 'example.txt', { type: 'text/plain' }),
progressHandler: ({ bytesTransferred }) => {
// Display progress using bytesTransferred / file's size
}
}).then(() => {
// file stored durably
}).catch((e) => console.error(e))
Parameters
-
databaseName [string | Len: 1-100] - The database name to use.
-
itemId [string | Len: 1-100] - The item's unique identifier.
-
file [File | Blob] - The file to upload.
Advanced Parameters
-
shareToken [string | optional] - The token used to access a shared database.
-
databaseId [string | optional] - The database's unique identifier.
-
progressHandler [function | optional] - A callback that gets invoked for each chunk the file uploads.
- bytesTransferred [number] - Total bytes uploaded to the server.
Errors
- ParamsMustBeObject
- DatabaseNotOpen
- DatabaseNameMissing
- DatabaseNameMustBeString
- DatabaseNameCannotBeBlank
- DatabaseNameTooLong
- DatabaseNameRestricted
- DatabaseIdMustBeString
- DatabaseIdCannotBeBlank
- DatabaseIdInvalidLength
- DatabaseIdNotAllowed
- DatabaseIsReadOnly
- ItemIdMissing
- ItemIdMustBeString
- ItemIdCannotBeBlank
- ItemIdTooLong
- ItemDoesNotExist
- FileMustBeFile
- FileCannotBeEmpty
- FileMissing
- FileUploadConflict
- TransactionUnauthorized
- UserNotSignedIn
- TooManyRequests
- ServiceUnavailable