Skip to content

Instantly share code, notes, and snippets.

@Manntrix
Created April 16, 2023 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Manntrix/a1acaf01617eee16077356282b9a690a to your computer and use it in GitHub Desktop.
Save Manntrix/a1acaf01617eee16077356282b9a690a to your computer and use it in GitHub Desktop.
const uploadFile = async () => {
const S3_BUCKET = "bucket-name";
const REGION = "region";
AWS.config.update({
accessKeyId: "youraccesskeyhere",
secretAccessKey: "yoursecretaccesskeyhere",
});
const s3 = new AWS.S3({
params: { Bucket: S3_BUCKET },
region: REGION,
});
const params = {
Bucket: S3_BUCKET,
Key: file.name,
Body: file,
};
var upload = s3
.putObject(params)
.on("httpUploadProgress", (evt) => {
console.log(
"Uploading " + parseInt((evt.loaded * 100) / evt.total) + "%"
);
})
.promise();
await upload.then((err, data) => {
console.log(err);
alert("File uploaded successfully.");
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment