@spacehq/sdk > UserStorage > addItems
UserStorage.addItems() method
addItems is used to upload files to buckets.
It uses an ReadableStream of Uint8Array data to read each files content to be uploaded.
Uploads will sequential and asynchronous with updates being delivered through the event emitter returned by the function.
Signature:
addItems(request: AddItemsRequest): Promise<AddItemsResponse>;
Parameters
Parameter | Type | Description |
---|---|---|
request | AddItemsRequest |
Returns:
Promise<AddItemsResponse>
Example
const spaceStorage = new UserStorage(spaceUser);
const response = await spaceStorage.addItems({
bucket: 'personal',
files: [
{
path: 'file.txt',
content: '',
mimeType: 'plain/text',
},
{
path: 'space.png',
content: '',
mimeType: 'image/png',
}
],
});
response.on('data', (data: AddItemsEventData) => {
const status = data as AddItemsStatus;
// update event on how each file is uploaded
});
response.on('error', (err: AddItemsEventData) => {
const status = data as AddItemsStatus;
// error event if a file upload fails
// status.error contains the error
});
response.once('done', (data: AddItemsEventData) => {
const summary = data as AddItemsResultSummary;
// returns a summary of all files and their upload status
});