adding pretteir and fixing post call so now clicking continue will upload to aws

This commit is contained in:
Will Baumbach
2025-07-26 20:36:14 -05:00
parent 61278967be
commit 2fed2636ad
8 changed files with 3222 additions and 2107 deletions

View File

@@ -1,16 +1,16 @@
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
import { Buffer } from 'node:buffer';
import { v4 as uuidv4 } from 'uuid';
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3'
import { Buffer } from 'node:buffer'
import { v4 as uuidv4 } from 'uuid'
class AWSUtil {
constructor() {
this.s3 = new S3Client({ region: "us-east-2" });
this.s3 = new S3Client({ region: 'us-east-2' })
}
async uploadFile(base64, ACL = "public-read") {
const base64Data = Buffer.from(base64.replace(/^data:image\/\w+;base64,/, ""), 'base64');
const type = base64.split(';')[0].split('/')[1];
const uuid = uuidv4();
async uploadFile(base64, ACL = 'public-read') {
const base64Data = Buffer.from(base64.replace(/^data:image\/\w+;base64,/, ''), 'base64')
const type = base64.split(';')[0].split('/')[1]
const uuid = uuidv4()
const params = {
Bucket: process.env.AWS_S3_BUCKET,
@@ -18,21 +18,16 @@ class AWSUtil {
Body: base64Data,
ContentEncoding: 'base64', // required
ContentType: `image/${type}` // required
};
}
// Create an object and upload it to the Amazon S3 bucket.
try {
const results = await this.s3.send(new PutObjectCommand(params));
const results = await this.s3.send(new PutObjectCommand(params))
console.log(
"Successfully created " +
params.Key +
" and uploaded it to " +
params.Bucket +
"/" +
params.Key
);
'Successfully created ' + params.Key + ' and uploaded it to ' + params.Bucket + '/' + params.Key
)
} catch (err) {
console.log("Error", err);
console.log('Error', err)
}
return `https://tattletires.s3.us-east-2.amazonaws.com/${params.Key}`
@@ -41,13 +36,13 @@ class AWSUtil {
async deleteFile(Location) {
const params = {
Bucket: process.env.AWS_S3_BUCKET,
Key: Location.split("s3.amazonaws.com/").pop()
};
Key: Location.split('s3.amazonaws.com/').pop()
}
const data = await this.s3.deleteObject(params).promise();
const data = await this.s3.deleteObject(params).promise()
return data;
return data
}
}
export default AWSUtil;
export default AWSUtil