Skip to main content

Storage

Squid Storage lets you securely manage uploads and downloads of fields.

Squid's storage feature lets you manage files with the Squid Client SDK so you can interface with your files from any client. Secure your files using the Squid Backend SDK for a seamless development and user experience. Use the built-in storage instance provided by Squid when creating an application, or connect your own AWS storage bucket.

Access the storage instance

To access the Squid storage instance, call .storage() on the Squid instance. For the built-in storage bucket, call the method without parameters. For any other storage integration, pass the integration ID.

Client code
squid.storage(); // accesses the built-in storage bucket

squid.storage('YOUR_INTEGRATION_ID'); // accesses a storage integration

Upload a file

To upload a file to storage, call the uploadFile() method, passing the directory path in the storage bucket where you want to store the file, the file in the form of a File or BlobAndFileName type. Use the File type for browsers and the BlobAndFileName type for Node.js applications.

Client code
await squid.storage().uploadFile('dir/path/in/bucket', yourFile);

BlobAndFileName has the following format:

{
blob: Blob;
name: string;
}

Get a file download URL

To download a file, generate a download URL using the getDownloadUrl() method, passing the path to the file and an optional expiration time in seconds. The default expiration time is 3600 seconds. This function returns a promise that resolves to an object containing the URL.

Client code
const urlResponse = await squid
.storage()
.getDownloadUrl('path/in/bucket/image.jpg', 7200);
console.log(urlResponse.url); // "https://prod-us-east-1-squid-storage.s3.amazonaws.com/abcd123..."

Get file metadata

To read metadata about a file, use the getFileMetadata() method, passing the path to the file.

Client code
const metadata = await squid
.storage()
.getFileMetadata('path/in/bucket/image.jpg');
console.log(metadata);
/*
{
filename: 'image.jpg',
size: 120672,
lastModified: Mon Mar 11 2024 17:32:00 GMT-0500 (Central Daylight Time)
}
*/

List directory contents

To list all contents of a given bucket directory, use the listDirectoryContents method, passing the bucket directory path.

Client code
const contents = await squid.storage().listDirectoryContents('path/in/bucket');
console.log(contents.directories);
/*
['documents/', 'contacts/']
*/

console.log(contents.files);
/*
[
{
filename: 'test.txt',
absoluteFilePathInBucket: 'path/in/bucket/test.txt',
lastModified: Mon Mar 11 2024 17:32:00 GMT-0500 (Central Daylight Time),
size: 9210
}, {
filename: 'image.jpg',
absoluteFilePathInBucket: 'path/in/bucket/image.jpg',
lastModified: Mon Mar 11 2024 17:34:16 GMT-0500 (Central Daylight Time),
size: 120672
},
]
*/

Delete a file

To delete a file, call the deleteFile() method, passing the path of the file to be deleted.

Client code
await squid.storage().deleteFile('path/in/bucket/image.jpg');

Delete multiple files

To delete more than one file, use the deleteFiles() method, passing an array of file paths.

Client code
await squid
.storage()
.deleteFiles(['path/in/bucket/image.jpg', 'path/in/bucket/test.txt']);

Securing a storage bucket

By default, all actions on a storage bucket are denied. To ensure only authorized access to storage bucket resources, use storage security functions. To learn more, view the Secure a storage bucket documentation.