Skip to Content
amazon s3 file upload using javascript
javascript code / April 22, 2018

Amazon Simple Storage Service (Amazon S3) is a mainstream web benefits that gives exceptionally adaptable, solid and secure stockpiling. Right now a large portion of us utilize server side answers for transfer records to Amazon S3 server. There are likewise AWS SDK for JavaScript to transfer documents to Amazon S3 server from customer side. Transferring records from customer side is speedier than server side and best for huge documents. So in this instructional exercise you will figure out how to transfer documents to Amazon S3 server utilizing JavaScript. The instructional exercise clarified in simple strides with live demo to transfer documents to Amazon S3 server. You can likewise download source code of live demo.

As we have secured this instructional exercise with live demo to transfer documents to Amazon s3 server with JavaScript, so the record structure for this case is following.

step by step code Here

step 1 create index.php

<title>phpcode : Demo Amazon S3 File Upload using JavaScript</title>
<script src=””></script>
<script src=”aws_config.js”></script>
<script src=”s3_upload.js”></script>
<?php include(‘container.php’);?>
<div class=”container”>
<h2>Amazon S3 File Upload using JavaScript</h2>
<form id=”uploadForm” method=’post’ enctype=”multipart/form-data”>
<h3>Upload File</h3><br/>
<span id=”showMessage” style=”display:none;color:red;”>File uploaded to Amazon server.</span>
<input type=’file’ name=”upFile” id=”upFile” required=”” />
<input type=’submit’ value=’Upload’/>
<div style=”margin:50px 0px 0px 0px;”>
<a class=”btn btn-default read-more” style=”background:#3399ff;color:white” href=”#”>Back</a>
<?php include(‘footer.php’);?>

step 2 created header.php

<!DOCTYPE html>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<link rel=”stylesheet” href=””>
<link rel=”stylesheet” href=””>
<script src=””></script>
<script src=””></script>
<!– jQuery –>

step 3 created footer.php

<div class=”insert-post-ads1″ style=”margin-top:20px;”>


step 4 created container.php

<body class=””>
<div role=”navigation” class=”navbar navbar-default navbar-static-top”>
<div class=”container”>
<div class=”navbar-header”>
<button data-target=”.navbar-collapse” data-toggle=”collapse” class=”navbar-toggle” type=”button”>
<span class=”sr-only”>#</span>
<span class=”icon-bar”></span>
<span class=”icon-bar”></span>
<span class=”icon-bar”></span>
<a href=”#” class=”navbar-brand”>PHPCODE</a>
<div class=”navbar-collapse collapse”>
<ul class=”nav navbar-nav”>
<li class=”active”><a href=”#”>Home</a></li>


</div><!–/.nav-collapse –>

<div class=”container” style=”min-height:500px;”>
<div class=”>

step 5 created s3_upload.js

$( document ).ready(function() {
$(“#uploadForm”).submit(function() {
var bucket = new AWS.S3({params: {Bucket: ‘BUCKET_NAME’}});
var uploadFiles = $(‘#upFile’)[0];
var upFile = uploadFiles.files[0];
if (upFile) {
var uploadParams = {Key:, ContentType: upFile.type, Body: upFile};
bucket.upload(uploadParams).on(‘httpUploadProgress’, function(evt) {
//console.log(“File Uploading: ” + parseInt((evt.loaded * 100) /’%’);
}).send(function(err, data) {
return false;

step 6 created aws_config.js

//AWS access info
accessKeyId : ‘ACCESS_KEY’,
secretAccessKey : ‘SECRET_KEY’
AWS.config.region = ‘YOUR REGION’;


PHPCODE © 2024