AWS::S3::Errors::InvalidArgument with Paperclip PDF Upload

amazon-s3, paperclip, pdf, ruby-on-rails

Solution

It turns out that switching to the aws-sdk gem requires the s3_permissions option to be a symbol. Changing `'authenticated_read'` to `:authenticated_read` fixes the issue.

Problem

I'm trying to upload a PDF to AWS S3 that is generated in a background process. The error I'm getting is a little cryptic and I was hoping someone had run into this or might be able to lead me in the right direction. I am using paperclip in other parts of the application, but these are taking form data where as this is creating a PDF and saving it to a local temp directory before uploading. Relevant gems: - Rails 3.0.9 - paperclip 2.7.0 - aws-sdk 1.3.9 code: ``` MyDownload < ActiveRecord::Base has_attached_file :download, storage: :s3, default_style: :original, s3_permissions: 'authenticated_read', s3_credentials: "#{Rails.root}/config/s3.yml", bucket: S3_BUCKET, path: ":class/:attachment/:id/:style/:filename", s3_protocol: 'https' validates_attachment_content_type :download, content_type: [/application\/(x\-)?pdf/i] validates_attachment_presence :download end ``` During my background process I know the PDF is generated and can be viewed at tmp_path. Here is a little bit of the code I'm using: ``` PDFKit.new(report_content).to_file(tmp_path) obj = MyDownload.new(date: Date.today) obj.download = File.new(tmp_path) obj.valid? # returns true ``` But it fails when I do: ``` obj.save! (AWS::S3::Errors::InvalidArgument) (eval):3:in `put_object' ```

Original source