Squid AI is designed to provide secure access to all of the tools you need to integrate your databases, APIs and services so you can focus on creating features rather than on boilerplate code. To that end, we’re excited to announce that Squid now integrates with AWS S3 storage buckets allowing you to access files from your client using the Squid Client SDK.
When creating a new Squid app, a built-in storage bucket is automatically created for both the dev and prod environments, allowing you to get up and running right away. Alternatively, if your app already has an S3 bucket (or even multiple buckets!), you can integrate them with Squid in minutes. Follow along with this post to learn how to use Squid’s storage functionality in your own apps.
Simple SDKs for complex problems
Your enterprise app might be complex, but your solutions don’t have to be! To upload a file, use the Squid Client SDK’s uploadFile
method, passing the directory path in the storage bucket where you want to store the file along with the file.
await squid.storage().uploadFile('dir/path/in/bucket', yourFile);
You can store images, JSON, PDFs, documents, or any other file type you need. To download a file, generate a download URL, passing the file’s full path as a string and an optional expiration time in seconds. You can then use the URL immediately, or store it in a database and easily access it later using the database functionality provided by the Squid Client SDK.
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>..."
To access your metadata, use the getFileMetadata
method. Use this method to get the size of the file and the date it was last modified.
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)
}
*/
Finally, to delete a file, use the deleteFile
method:
await squid.storage().deleteFile('path/in/bucket/image.jpg');
These simple methods worth together to give you full control over your storage buckets. More importantly, like all Squid client features, the Squid Backend SDK provides a decorator to let you easily customize your role-based access controls.
Fully customizable security functionality
Using a Squid Storage integration allows you to access the @secureStorage
decorator in the Squid backend, letting you write security functions that are as simple or complex as your app requires. For example, this function allows users to upload files to the storage bucket if they are writing them to their own assigned directory based on their user ID:
// Allow clients to upload files to the `user/{uid}` directory
@secureStorage('write', 'built_in_storage')
allowWriteOwnStorage(context: StorageContext): boolean {
const userId = this.getUserAuth().userId;
for (const path of context.pathsInBucket) {
if (!path.startsWith(`user/${userId}`)) {
return false;
}
}
return true;
}
For details on securing Squid storage buckets, check out the documentation.
Find out what’s in store
Here at Squid, we’re continuously improving our platform by adding new features and integrations. To find out about the latest features of Squid, join our Discord server or follow us on LinkedIn or X. To learn about other available functionality of Squid, check out our tutorials and code samples. We can’t wait to see what you build!