How to upload to AWS S3 directly from browser using a pre-signed URL instead of credentials?

后端 未结 7 1195
天命终不由人
天命终不由人 2020-12-08 03:07

We\'d like to use Javascript AWS SDK to upload files to S3, but without using credentials at all. Uploading using credentials works, but we cannot generate an AWS IAM user f

7条回答
  •  没有蜡笔的小新
    2020-12-08 03:32

    I prefer this cleaner approach, via github:

    If you already have a presigned URL generated for the browser, you can simply send an XHR request with that URL and the payload to upload to S3. The SDK would not be required to do this. A jQuery example below:

    $.ajax({
      url: presignedUrl, // the presigned URL
      type: 'PUT',
      data: 'data to upload into URL',
      success: function() { console.log('Uploaded data successfully.'); }
    });
    

提交回复
热议问题