Basically you need this S3Client Package from aws-sdk to upload a file to s3 bucket.
import { S3Client, PutObjectCommand, GetObjectCommand } from "@aws-sdk/client-s3";
private static async uploadPhotoToAWS(blob: Blob, opts?: CaptureOptions) {
if (!opts?.aws) {
showBalloonError("AWS configuration is missing");
return false;
}
const { region, bucketName, accessKeyId, secretAccessKey } = opts.aws;
const client = new S3Client({
region,
credentials: {
accessKeyId,
secretAccessKey,
},
});
const format = this.recordingFormat;
const ext = format.split("/")[1];
let fileName = "needle-engine-facefilter";
if (opts?.file_name?.length && hasProLicense()) {
fileName = opts.file_name;
}
fileName += "." + ext;
try {
const command = new PutObjectCommand({
Bucket: bucketName,
Key: fileName,
Body: blob,
ContentType: format,
});
this.showSpinner("Uploading file, please wait")
const response = await client.send(command);
this.hideSpinner();
// Generate a presigned URL for downloading
const getObjectCommand = new GetObjectCommand({
Bucket: bucketName,
Key: fileName,
});
return true;
} catch (error) {
console.error("Error uploading to AWS S3:", error);
showBalloonError("Failed to upload file to AWS S3");
return false;
}
}