简体   繁体   English

删除文件不适用于 cors,但上传适用于使用 AWS S3 存储桶的 cors

[英]Delete file doesn't work with cors but upload works with cors with AWS S3 bucket

I'm using react-s3 for uploading and deleting file from s3.我正在使用 react-s3 从 s3 上传和删除文件。 When the bucket is public, it works fine for both methods but when it is set to private, only upload file works and delete file throws error:当存储桶是公共的时,这两种方法都可以正常工作,但是当它设置为私有时,只有上传文件有效,删除文件会引发错误:

type: "cors"
url: "https://mylink.myfile"
redirected: false
status: 403
ok: false
statusText: "Forbidden"

Also this is what I put for CORS config:这也是我为 CORS 配置设置的内容:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>HEAD</AllowedMethod>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedMethod>PUT</AllowedMethod>
    <AllowedMethod>POST</AllowedMethod>
    <AllowedMethod>DELETE</AllowedMethod>
    <ExposeHeader>ETag</ExposeHeader>
    <AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>

Why is this happening and how can I fix this为什么会发生这种情况,我该如何解决这个问题

You must be generating the presigned URL for putObject only.您必须仅为putObject生成预签名 URL。 Deletion does not supported through presigned URLs.不支持通过预签名 URL 进行删除。 it is only supported for GET and PUT .它仅支持GETPUT consider doing deletion using server side code after carefully checking whether or not the deletion should be allowed.在仔细检查是否允许删除后,考虑使用服务器端代码进行删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM