AWS S3 file upload with progress bar using javascript sdk

17 / Jun / 2015 by Deepak Kumar Mittal 4 comments

You can upload files on AWS S3 using a server side solution, but in case of larger files it is advisable to use a client side solution. You can probably use JavaScript file upload feature of AWS S3. This is simple three step feature as described below:

Step 1 : In the head section of your page include javascript sdk and specify your keys like this:

<script src=""></script>
<script type="text/javascript">
        accessKeyId : 'ACCESS_KEY',
        secretAccessKey : 'SECRET_KEY'
    AWS.config.region = 'AWS_REGION';

Step 2 : Now create a simple html form with a file input.

<form id="fileUploadForm" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file" value="dataFile" required="">

Step 3 : Now upload your input file to S3

$("#fileUploadForm").submit(function() {
var bucket = new AWS.S3({params: {Bucket: 'BUCKET_NAME'}});
var fileChooser = document.getElementById('file');
var file = fileChooser.files[0];
if (file) {
var params = {Key: 'FILE_NAME', ContentType: file.type, Body: file};
bucket.upload(params).on('httpUploadProgress', function(evt) {
console.log("Uploaded :: " + parseInt((evt.loaded * 100) /'%');
}).send(function(err, data) {
alert("File uploaded successfully.");
return false;

To upload the file successfully, you need to enable CORS configuration on S3.

Generally, it is not advisable to display your keys directly on page, so you can use Amazon Cognito or web identity federation feature.

Know more 

Tag -


comments (4)

  1. tarun singh

    How can I upload 100GB AEM package using AWS s3 ? I am getting errors as the internal division of the package is exceeding the part-limits. And also, if you can tell me how to change that upload part-limit?

  2. Thor

    “Step 1: Put your SECRET ACCESS KEY in the header of your client-side file, for the world to see! What could go wrong?”


Leave a comment -