Error When Using Paperclip and S3
-
Matt Darby
- Tag set to aws, paperclip
- State changed from new to open
Can you post your Paperclip model config? What does @model.paperclip_attribute.url return? Could it be that Paperclip is setup to tell AWS to make the S3 files private? Scribd can't touch files that need authentication...
-
shai.shefer (at gmail)
Sure.
Here is my Paperclip snippet from my document model. The model itself is polymorphic.
belongs_to :documentable, :polymorphic => true has_attached_file :clip, :storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/s3.yml", :bucket => "#{APP_CONFIG[:bucket]}", :path => ":attachment/:id/:basename.:extension" validates_presence_of :name validates_attachment_size :clip, :less_than => 5.megabytes, :message => "file size is more than 5 megabytes"The default permission with Paperclip is "public-read".
Calling @document.clip.url returns:
https://s3.amazonaws.com/BUCKET/... on cash flow.doc
Calling s3_url using the method described in the previous post returns:
https://s3.amazonaws.com:443/BUC...
As stated earlier, the second link will work with the Scribd uploader while the first one will not.
-
shai.shefer (at gmail)
I should add that:
https://s3.amazonaws.com/BUCKET/ATTRIBUTE/1/Focus%20on%20cash%20flow.docIS accessible. So maybe there is just the need to sanitize the attribute.url returned.
-
Matt Darby
- State changed from open to resolved
Yep, looks spaces in the filename is what killed it. AttachmentFu modifies the filename on save, but Paperclip does not.
Pushed out the 2.0.3 gem with the fix.
-
shai.shefer (at gmail)
Note / Update
I've tried calling CGI::escape on the attribute.url and the provided link still doesn't seem to work with the Scribd uploader.
-
Matt Darby
CGI::escape encodes the URL, whereas what we need is a simple gsub(' ', '%20')...
>> Attachment.last.file_path => "https://s3.amazonaws.com/content.dynamixccw.com/attachments/4/Financial goal Report.pdf" >> url = _ => "https://s3.amazonaws.com/content.dynamixccw.com/attachments/4/Financial goal Report.pdf" >> CGI::escape(url) => "https%3A%2F%2Fs3.amazonaws.com%2Fcontent.dynamixccw.com%2Fattachments%2F4%2FFinancial+goal+Report.pdf" >> url.gsub(' ', '%20') => "https://s3.amazonaws.com/content.dynamixccw.com/attachments/4/Financial%20goal%20Report.pdf" -
shai.shefer (at gmail)
- Assigned user cleared.
Yup - sorry about that.
Started writing that comment before 7PM.
-
egenial
- Assigned user set to Matt Darby
I'm having a similar problem, I'm using version 2.0.5 of scribd_fu. If I do not use the amazon, and write local files, works just fine.
ScribdFu::ScribdFuUploadError (Sorry, but Presentation #48 could not be uploaded to Scribd):
/Library/Ruby/Gems/1.8/gems/scribd_fu-2.0.5/lib/scribd_fu.rb:72:inupload' /Library/Ruby/Gems/1.8/gems/scribd_fu-2.0.5/lib/scribd_fu.rb:184:inupload_to_scribd'My model:
class Presentation < ActiveRecord::Base#validates_attachment_content_type :document, :content_type => ['application/vnd.ms-powerpoint']
has_attached_file :document,
:storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/s3.yml", :bucket => "my_bucket", :path => ":attachment/:id/:basename.:extension"has_ipaper_and_uses 'Paperclip'
end
My @model.document.url return this url http://s3.amazonaws.com/my_bucket/documents/49/imersao-dia3.ppt
Can you give me a help to solve this little problem?
-
Matt Darby
- Tag cleared.
Can you comment out lines 68 and 71-73 in scribd_fu.rb, restart your app and try again? Does it produce an error? What is it?
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.