I'm using react-s3 for uploading and deleting file from 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:
<?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. Deletion does not supported through presigned URLs. it is only supported for GET
and PUT
. consider doing deletion using server side code after carefully checking whether or not the deletion should be allowed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.