简体   繁体   English

Rails回形针S3附件未删除(错误请求)

[英]Rails paperclip S3 attachment not deleted (bad request)

I'm developing a rails API. 我正在开发一个rails API。 I use the paperclip gem to store images in Amazon S3. 我使用paperclip gem在Amazon S3中存储图像。 I'm just using my own access key for the bucket, without any added policies. 我只是使用自己的存储桶访问密钥,没有任何添加的策略。 The attachments are correctly uploaded and stored in S3, but when I destroy a record, the attachments are not deleted. 附件已正确上载并存储在S3中,但是当我销毁记录时,附件不会被删除。 I also tried deleting the attachment alone, and that gave the following error: 我也尝试单独删除附件,这给出了以下错误:

[AWS S3 400 0.382023 0 retries] head_object(:bucket_name=>"my-bucket-name",:key=>"the/url/to/the/image.jpg") AWS::S3::Errors::BadRequest AWS::S3::Errors::BadRequest

In my model: 在我的模型中:

has_attached_file :main_image
validates_attachment :main_image, presence: true,
                     content_type: { content_type: %w(image/jpeg image/png)},
                     size: { in: 0 .. 1.megabytes }

In my configuration: 在我的配置中:

# Paperclip config
config.paperclip_defaults = {
    storage: :s3,
    s3_credentials: {
        bucket: ENV.fetch('AWS_S3_BUCKET'),
        access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
        secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
        s3_region: ENV.fetch('AWS_S3_REGION'),
    }
}

The app is running on Heroku. 该应用程序在Heroku上运行。 Is this a permissions issue? 这是权限问题吗? Note that I'm using the aws-sdk gem version 1.66. 请注意,我使用的是aws-sdk gem版本1.66。

This is a permissions issue with AWS S3 since you are able to upload but not delete. 这是AWS S3的权限问题,因为您可以上载但不能删除。 Did you create an AWS IAM user to generate an Access Key and Secret Key? 您是否创建了AWS IAM用户来生成访问密钥和密钥? If so can you paste your policy? 如果是这样,你可以粘贴你的政策吗

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

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