I am working on a Django app and trying to upload files in the front end to bypass Heroku's timeout. However, I am struggling to get my code to function correctly.
<script type="text/javascript">
AWS.config.update({
region: 'us-east-1',
credentials: new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'MY-IDENTITY-POOL-ID',
})
});
var s3 = new AWS.S3({
apiVersion: '2006-03-01',
params: {Bucket: 'MYBUCKETNAME'}
});
<script type="text/javascript">
function s3upload() {
var files = document.getElementById('fileUpload').files;
if (files)
{
var file = files[0];
var fileName = file.name;
var fileUrl = 'https://' + 'MYBUCKETNAME.s3.' + 'us-east-1' + '.amazonaws.com/' + fileName;
alert(fileUrl)
var s3 = new AWS.S3({
apiVersion: '2006-03-01',
params: {Bucket: 'MYBUCKETNAME'}
});
s3.upload({
Key: fileName,
Body: file,
ACL: 'public-read'
}, function(err, data) {
if(err) {
reject('error');
}
alert('Successfully Uploaded!');
});
}
};
</script>
I am aware that there might be an issue with how I am passing variables to the AWS API as this is my first time using this method. Can someone guide me on the correct way to structure the API variables above? The documentation available is quite confusing.