Created
April 16, 2023 08:43
-
-
Save Manntrix/a1acaf01617eee16077356282b9a690a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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