#1 ✓resolved
shai.shefer (at gmail)

Error When Using Paperclip and S3

Reported by shai.shefer (at gmail) | April 5th, 2009 @ 10:30 PM

When using Paperclip and S3 for storage the following error appears:

Sorry, but Document #9 could not be uploaded to Scribd


/vendor/gems/mdarby-scribd_fu-2.0.2/lib/scribd_fu.rb:68:in `upload'
/vendor/gems/mdarby-scribd_fu-2.0.2/lib/scribd_fu.rb:177:in `upload_to_scribd'

I think it may be traced back to lib/scribd_fu/paperclip.rb line 37 and the file_path method:


def file_path
  if attached_file.url =~ /^https{0,1}:\/\/s3.amazonaws.com$/
    attached_file.url
  else
    attached_file.path
  end
end

Loading up the console and taking the output of paperclip_attribute.url to place into the Scribd url uploader (http://www.scribd.com/upload/url) returns an error.

I know that the following solution will work to provide a valid and authenticated link to an uploaded document:


def s3_url
  self.PAPERCLIP_ATTRIBUTE.s3.interface.get_link(PAPERCLIP_ATTRIBUTE.s3_bucket.to_s, PAPERCLIP_ATTRIBUTE.path)
end

Paperclip is dependent on right_aws for S3 and the interface.get_link can provide a secure link that can be used independently in the Scribd url uploader already specified. I am just not sure how to integrate this into the existing code base. The only required perquisite is to load the s3 config file.

I may be totally off on the solution to this, just my guess after looking around at the code.

Comments and changes to this ticket

  • Matt Darby

    Matt Darby April 6th, 2009 @ 07:54 AM

    • 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)

    shai.shefer (at gmail) April 6th, 2009 @ 11:06 AM

    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)

    shai.shefer (at gmail) April 6th, 2009 @ 11:57 AM

    I should add that:

    
    https://s3.amazonaws.com/BUCKET/ATTRIBUTE/1/Focus%20on%20cash%20flow.doc
    

    IS accessible. So maybe there is just the need to sanitize the attribute.url returned.

  • Matt Darby

    Matt Darby April 6th, 2009 @ 07:04 PM

    • 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)

    shai.shefer (at gmail) April 6th, 2009 @ 07:12 PM

    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

    Matt Darby April 6th, 2009 @ 07:14 PM

    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)

    shai.shefer (at gmail) April 6th, 2009 @ 07:24 PM

    • Assigned user cleared.

    Yup - sorry about that.

    Started writing that comment before 7PM.

  • egenial

    egenial November 26th, 2009 @ 09:28 PM

    • 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:in upload' /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

    Matt Darby November 27th, 2009 @ 12:34 AM

    • 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.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

A Ruby on Rails plugin that streamlines interaction with Scribd.com’s iPaper service, and works along side of either Attachment_fu or Paperclip.

Pages