Read PDF from web and store it in S3 bucket - ruby-on-rails-3

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.

Related

KeystoneJS S3 Image Upload from TinyMCE WYSIWYG

I can't seem to find any documentation on converting the KeystoneJS TinyMCE wysiwyg to accept image files to upload to S3. I have added the following to my init (some as a failsafe/testing):
'wysiwyg additional plugins': 'uploadimage',
'wysiwyg images': true,
'wysiwyg s3 images': true,
Upon investigation, it seems that Keystone recognizes 'wysiwyg s3 images' but is trying to activate the uploadimage plugin that no longer exists in node_modules/admin/public/js/lib/tinymce/plugins.
I am running Node#10.15.0, NPM#6.7.0, and KeystoneJS#4.0.0-beta.5
Updating keystone from version 4.0.0-beta.5 to version 4.0.0 helped me to avoid the tinymce plugin problem.

Getting content length is not supported in Yii EAjaxUpload

I am using Yii EAjaxUpload extension to upload files. I am facing a problem during uploading image. 'Getting content length is not supported'. In console It is showing the error "http://46.101.98.121/MyApp/index.php?r=controller/upload&PHPSESSID=j7…KEN=077cb06478a3c70e40a2a01dc4cb1a94a6ff96ec&qqfile=518164-backgrounds.jpg". In php.ini 'upload_max_filesize' and 'post_max_size' both are 100MB. File is already uploaded to the destination folder but the uploading procedure fails each time. Please help.

Filebrowser showing IOError while uploading files(images,docs etc.......)

In django CMS project...i used filebrowser for file uploading .But Filebrowser showing IOError while uploading files in django python 1.4.1.
Anyone who solved this one ,please answer or give me any solution.
While uploading images or documents using filebrowser the image/document is uploaded but always showing error....

pdfkit not rendering correctly in rails 3.1

I have followed the following railscast about adding pdfkit to an application, and I am having some issues with the generation of pdfs. Here are the following things that I have done:
I downloaded wkhtmltopdf via the homebrew package manager
brew install wkhtmltopdf
Then I added the pdfkit gem to my gemfile and ran the bundle install command. I added the following to my config/application.rb file
require 'pdfkit'
...
config.middleware.use PDFKit::Middleware, :print_media_type => true
I then changed my application layout file to include all stylesheet types.
If I run rake middleware, the command works and I can see the pdfkit middleware
When I try to append pdf to the end of my routes the application just hangs and I have to exit via the command line. If I create a link to the page I want to make into a pdf, it changes all of the markup so it looks like a corrupted file. (it looks like you opened a text file into a word processor or vice versa I can provide images if that helps) If I try to make css changes in my stylesheet they do not go into effect when I view them with the link to pdf. I am assuming that this has something to do with the new asset pipeline in rails has anyone else experienced this issue?
So I was right in assuming that my error had something to do with the asset pipeline, after doing some research it looks like you need to create a new initializer and add the following code:
ActionController::Base.asset_host = Proc.new { |source, request|
if request.env["REQUEST_PATH"].include? ".pdf"
"file://#{Rails.root.join('public')}"
else
"#{request.protocol}#{request.host_with_port}"
end
}

Uploads silently failing/pausing with new carrierwave_direct gem when uploading to s3

i am having a small problem uploading files to s3 with new carrierwave_direct gem
I have followed the instructions for installing and setting up carrierwave_direct, however when i try to upload to s3, the upload begins and then pauses the upload at some point. Any thoughts?
Also sometimes i get this message from s3:
<Error>
<Code>InvalidPolicyDocument</Code>
<Message>
Invalid Policy: Invalid 'expiration' value: '2011-09-13T07:52:58+02:00'
</Message>
<RequestId>"some id"</RequestId>
<HostId>
"some host id"
</HostId>
</Error>
I have created an initializes file called carrierwave.rb with all my credentials from amazon s3. I have also loaded all the required gems(carrierwave_direct, fog, carrierwave)
Checkout my code here on gist
Has anybody else been able to get this working
Thank for for the help
I would try removing this line from your carrierwave_fog.rb config:
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {}
It sounds like your document expiration date is invalid because it is too close to the current date/time.
Also, you may need to uncomment your #storage :fog line in your ImageUploader.
See if that helps.
The author of this gem had found that the problem was with rails 3.0.x versions, to make this gem work you need to add the following line to config/application.rb:
config.action_controller.allow_forgery_protection = false
and remove the following from my carrierwave.rb file in config/initilizers:
config.fog_host = 'https://#{fog_directory}.s3.amazonaws.com'
as this will automatically be determined by the fog directory.
The author mentioned as well that if you are using rails 3.1.x you do not need to perform the above mentioned steps. Hope this helps