Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you access the raw content of a file uploaded with Paperclip / Ruby on Rails?

I'm using Paperclip / S3 for file uploading. I upload text-like files (not .txt, but they are essentially a .txt). In a show controller, I want to be able to get the contents of the uploaded file, but don't see contents as one of its attributes. What can I do here?

attachment_file_name: "test.md", attachment_content_type: "application/octet-stream", attachment_file_size: 58, attachment_updated_at: "2011-06-22 01:01:40" 

PS - Seems like all the Paperclip tutorials are about images, not text files.

like image 675
Geoff Avatar asked Jul 02 '11 06:07

Geoff


1 Answers

In Paperclip 3.0.1 you could just use the io_adapter which doesn't require writing an extra file to (and removing from) the local file system.

Paperclip.io_adapters.for(attachment.file).read 
like image 120
jwadsack Avatar answered Oct 03 '22 04:10

jwadsack