0

I am doing a project using ruby on rails which requires reading a pdf from web(link provided by users) and store in amazon S3 bucket.

Rails version 3.2

Ruby version 2.1.5

My sample code

require 'open-uri'
data = open('http://www.cbu.edu.zm/downloads/pdf-sample.pdf')

path = "pdf_files/123/sample.pdf"
AwsWrapper::S3Object.store(path, data, S3_CONFIG[:bucket], :content_type => 'pdf')

Above code stores that file in S3 but while opening the file I can't see data. It showing error message like Failed to load PDF document I am new to RoR. Please help me. Thanks in advance.

  • Troubleshooting 101: write the data to a local file, first, and see if it is valid. Also `:content_type => 'application/pdf'` is the [correct](http://stackoverflow.com/a/312258/1695906) MIME type to use, which could be the problem, too. – Michael - sqlbot Sep 21 '15 at 22:25
  • @Michael-sqlbot Yes, Its working now. thanks for your solution. – user2194445 Sep 24 '15 at 09:18

0 Answers0