Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Looking for elegant way to force attachment's content_type #1338

Closed
Capncavedan opened this issue Sep 9, 2013 · 3 comments
Closed

Looking for elegant way to force attachment's content_type #1338

Capncavedan opened this issue Sep 9, 2013 · 3 comments

Comments

@Capncavedan
Copy link

We fetch some binary PDF data and store it as an S3 attachment. The file name Paperclip assigns is "stringio.txt" and the content_type in Rails is nil; on S3 the metadata indicates the content_type is "text/plain". This causes a problem in Chrome as it doesn't deal with the download properly.

We're looking for a way to force the attachment's content_type. Below is what we've found but it seems uglier than necessary. Note that pdf_data is a method on the model that returns binary PDF data.


  has_attached_file :pdf,
    storage:          :s3,
    # etc


  # before, getting text/plain as content_type set on S3
  def render_pdf
    self.pdf = StringIO.new(pdf_data)
    save
  end


  # after, getting application/pdf as content_type on S3
  def render_pdf
    io = StringIO.new(pdf_data)
    def io.content_type; 'application/pdf'; end
    self.pdf = io
    save
  end

Any suggestions appreciated.

@maclover7
Copy link
Contributor

Hi @Capncavedan ! Is this still an issue for you in Paperclip; I know this issue is from approximately 2 years ago. If it is still an issue, can you please provide the code that's causing you the error? Thanks!

@Capncavedan
Copy link
Author

Unsure if still an issue with current Paperclip. Our workaround shown above continues to work with Paperclip 3.5.4. Feel free to close this issue.

@maclover7
Copy link
Contributor

@jferris @jyurek Please close issue, problem appears to be solved.

@tute tute closed this as completed May 9, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants