Learn how to integrate Bolt.new AI with AWS S3 in this easy guide. Follow our step-by-step instructions for seamless cloud storage and AI automation.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
awsS3.ts
.
package.json
if available) or include a script tag if the platform supports it.package.json
file, add:
{
"dependencies": {
"aws-sdk": "^2.1370.0"
}
}
package.json
file directly, please check Bolt.new AI documentation for adding external packages.
awsS3.ts
:
import AWS from 'aws-sdk';
const s3 = new AWS.S3({
accessKeyId: process.env.AWSACCESSKEY_ID,
secretAccessKey: process.env.AWSSECRETACCESS_KEY,
region: process.env.AWS_REGION
});
export interface UploadParams {
Bucket: string;
Key: string;
Body: Buffer | Uint8Array | Blob | string;
ACL?: string;
}
export const uploadFile = async (params: UploadParams): Promise<AWS.S3.ManagedUpload.SendData> => {
try {
const uploadResult = await s3.upload(params).promise();
console.log('Upload successful:', uploadResult);
return uploadResult;
} catch (error) {
console.error('Error during S3 upload:', error);
throw error;
}
};
uploadFile
to handle file uploads.
index.ts
or another appropriate entry point).uploadFile
function so you can use it within your project:
import { uploadFile, UploadParams } from './awsS3';
UploadParams
object and call uploadFile
:
// Example usage in your main file
const fileContent = 'This is the content of the file.';
const params: UploadParams = {
Bucket: process.env.S3_BUCKET!, // using the S3 bucket from your environment variables
Key: 'folder/yourfile.txt', // the path and name where the file will be stored
Body: fileContent,
ACL: 'public-read' // optional: set file permissions
};
uploadFile(params)
.then(result => {
console.log('File uploaded successfully:', result);
})
.catch(error => {
console.error('Upload error:', error);
});
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.