Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8553481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:39:44+00:00 2026-06-11T14:39:44+00:00

I am developing a website in HTML, javascript & jQuery. I want to upload

  • 0

I am developing a website in HTML, javascript & jQuery. I want to upload images to amazon s3 server in an ajax request. There is no such SDK to integrate s3 in Javascript. A PHP SDK is available, but it is not useful to me. Can anybody provide solution to this in javascript?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:39:45+00:00Added an answer on June 11, 2026 at 2:39 pm

    Got Amazon S3 & CORS working on js and html5 using XMLHTTPObject based on this article article.

    1: CORS only works from a proper URL “http://localhost“. (file///xyz will make you go insane)

    2 : Make sure you got the POLICY and Secret compiled correctly – here is my policy and this is the link you can get the project to get you started with Signature and Policy — do not publish this JS with your Secret EVER!

    POLICY_JSON = { "expiration": "2020-12-01T12:00:00.000Z",
                "conditions": [
                {"bucket": this.get('bucket')},
                ["starts-with", "$key", ""],
                {"acl": this.get('acl')},                           
                ["starts-with", "$Content-Type", ""],
                ["content-length-range", 0, 524288000]
                ]
              };
    
    
        var secret = this.get('AWSSecretKeyId');
        var policyBase64 = Base64.encode(JSON.stringify(POLICY_JSON));
        console.log ( policyBase64 )
    
        var signature = b64_hmac_sha1(secret, policyBase64);
        b64_hmac_sha1(secret, policyBase64);
        console.log( signature);
    

    Here is the JS code

    function uploadFile() {
    
        var file = document.getElementById('file').files[0];
        var fd = new FormData();
    
        var key = "events/" + (new Date).getTime() + '-' + file.name;
    
        fd.append('key', key);
        fd.append('acl', 'public-read'); 
        fd.append('Content-Type', file.type);      
        fd.append('AWSAccessKeyId', 'YOUR ACCESS KEY');
        fd.append('policy', 'YOUR POLICY')
        fd.append('signature','YOUR SIGNATURE');
    
        fd.append("file",file);
    
        var xhr = new XMLHttpRequest();
    
        xhr.upload.addEventListener("progress", uploadProgress, false);
        xhr.addEventListener("load", uploadComplete, false);
        xhr.addEventListener("error", uploadFailed, false);
        xhr.addEventListener("abort", uploadCanceled, false);
    
        xhr.open('POST', 'https://<yourbucket>.s3.amazonaws.com/', true); //MUST BE LAST LINE BEFORE YOU SEND 
    
        xhr.send(fd);
      }
    

    Helper functions

    function uploadProgress(evt) {
        if (evt.lengthComputable) {
          var percentComplete = Math.round(evt.loaded * 100 / evt.total);
          document.getElementById('progressNumber').innerHTML = percentComplete.toString() + '%';
        }
        else {
          document.getElementById('progressNumber').innerHTML = 'unable to compute';
        }
      }
    
      function uploadComplete(evt) {
        /* This event is raised when the server send back a response */
        alert("Done - " + evt.target.responseText );
      }
    
      function uploadFailed(evt) {
        alert("There was an error attempting to upload the file." + evt);
      }
    
      function uploadCanceled(evt) {
        alert("The upload has been canceled by the user or the browser dropped the connection.");
      }
    

    Then the HTML Form

     <form id="form1" enctype="multipart/form-data" method="post">
    <div class="row">
      <label for="file">Select a File to Upload</label><br />
      <input type="file" name="file" id="file" onchange="fileSelected()"/>
    </div>
    <div id="fileName"></div>
    <div id="fileSize"></div>
    <div id="fileType"></div>
    <div class="row">
      <input type="button" onclick="uploadFile()" value="Upload" />
    </div>
    <div id="progressNumber"></div>
    

    Happy CORS-ing!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a website (Wordpress, HTML, CSS, jQuery) with contents written in portuguese. There
I'm developing an Adobe Air app using JavaScript. I want to get HTML content
I'm very new in web developing. I'm developing a website by using HTML, jQuery,
At my website I've been developing an RPG based game with Html and Javascript;
I'm developing this website: http://parkoura.tk/a/sandbox/ I am using an ajax navigation. I have a
I'm developing a website and I'd like the users be able to upload files
I'm developing a small app designed to embed HTML + JavaScript (JavaScript manages the
Greetings. I am developing an animated homepage for a Flash-HTML hybrid website, and for
I'm developing a mobile website in HTML/HTML5. This is NOT an iOS app but
I am developing a website in which i need to open a HTML page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.