Javascript 如何使用xmlhttprequest将文件上载到aws s3
如何使用xmlhttprequest将文件上载到s3。我试着按照这个方法做,但我犯了如下错误 “此操作禁止匿名访问” 这是我的密码:Javascript 如何使用xmlhttprequest将文件上载到aws s3,javascript,amazon-s3,Javascript,Amazon S3,如何使用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',
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以允许交叉发布。相关问题如何做到这一点:您是否已将(post,PUT)的CORS配置为bucket上的allowmethods?是的,我已将(post,PUT)的CORS配置为。但我得到了如下回应,如“此操作禁止匿名访问”,这可能会对您有所帮助。