簡體   English   中英

如何使用xmlhttprequest將文件上傳到AWS S3

[英]How to upload file to aws s3 using xmlhttprequest

如何使用xmlhttprequest將文件上傳到s3。 我嘗試了以下方式,但出現了類似的錯誤

“此操作禁止匿名訪問”。

這是我的代碼:

const xhr = new XMLHttpRequest();
xhr.open('PUT', "https://region.amazonaws.com/bucket-name/");
xhr.setRequestHeader('X-Amz-ACL', 'public-read');
xhr.setRequestHeader('Content-Type', 'image/png');
xhr.send({
    file: file,
    type: 'image/png',
    name: "myfile_9898_0",
    acl: 'public-read',
    AWSAccessKeyId: 'aws key',
    AWSSecreKeyId: 'scret_key'
});

這段代碼有什么問題嗎?
誰能幫我?

您拼寫的SecretKey錯誤。

但是,任何人瀏覽此頁面(假設它位於html頁面中)都可以竊取您的憑據! 將secretKey放在任何地方都是一個壞主意-最好使用您的秘密在服務器上生成一個“預簽名密鑰”。 您還需要在服務器上設置CORS以允許交叉發布。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM