Rack, Paperclip, grape file upload example

581 views
Skip to first unread message

Loren Harrell

unread,
Jun 3, 2013, 4:10:49 PM6/3/13
to ruby-...@googlegroups.com
Can someone please reply with working example processing a file upload request? I can't seem to get my api to properly upload with grape.

Here is what I have so far:

  namespace...
    post ':person_id/avatar' do
    person = Person.find_by_id(params[:person_id])
    file = params['image_file'] ? params['image_file']['tempfile'] : nil
    unless file.blank?
      person.avatar = file
      person.save!
      end
    end

Then when I use:
curl -F "image_file=@/home/me/myfile.jpg" http://mysite.com/upload

I get exception thrown that my file type is not valid because original_filename has been set to the 'RackMultipart20130602-79blahblah', not myfile.jpg.

What Am I missing?

Daniel Doubrovkine

unread,
Jun 3, 2013, 9:05:20 PM6/3/13
to ruby-...@googlegroups.com
I added a demo to https://github.com/dblock/grape-on-rack/https://github.com/dblock/grape-on-rack/blob/master/api/upload_file.rb. It worked with curl as well, without any changes.

Post the entire exception, please.


--
You received this message because you are subscribed to the Google Groups "Grape Framework Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-grape+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--

dB. | Moscow - Geneva - Seattle - New York
code.dblock.org - @dblockdotorg - artsy.net - github/dblock

Reply all
Reply to author
Forward
0 new messages