-
Notifications
You must be signed in to change notification settings - Fork 27
/
aws-s3-bucket-upload.html
67 lines (57 loc) · 2.21 KB
/
aws-s3-bucket-upload.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!doctype html>
<head>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.357.0.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
//Bucket Configurations
var bucketName = BUCKET_NAME;
var bucketRegion = BUCKET_REGION;
var IdentityPoolId = IDENTITY_POOL_ID;
AWS.config.update({
region: bucketRegion,
credentials: new AWS.CognitoIdentityCredentials({
IdentityPoolId: IdentityPoolId
})
});
var s3 = new AWS.S3({
apiVersion: '2006-03-01',
params: {Bucket: bucketName}
});
</script>
</head>
<body>
<!-- A functional html code-->
<div>
<input type="file" id="fileUpload">
</div>
<div>
<button onclick="s3upload()">Submit</button>
</div>
<progress max=”100” value=”0”></progress>
<script type="text/javascript">
function s3upload() {
var files = document.getElementById('fileUpload').files;
if (files)
{
var file = files[0];
var fileName = file.name;
var filePath = 'my-first-bucket-path/' + fileName;
var fileUrl = 'https://' + BUCKET_REGION + '.amazonaws.com/my-first-bucket/' + filePath;
s3.upload({
Key: filePath,
Body: file,
ACL: 'public-read'
}, function(err, data) {
if(err) {
reject('error');
}
alert('Successfully Uploaded!');
}).on('httpUploadProgress', function (progress) {
var uploaded = parseInt((progress.loaded * 100) / progress.total);
$("progress").attr('value', uploaded);
});
}
};
</script>
</body>
</html>