CuriousNewbie
2011-Jan-24 22:22 UTC
Rails Accessing an Uploaded File and Saving it to PaperClip
Hello, I''m using the following file uploader with Rails 3:
https://github.com/blueimp/jQuery-File-Upload
The uploader on the client side is working fine. I can see in the
Rails log file that the following is being posted when I upload a
file:
Started POST "/attachments/upload" for 127.0.0.1 at Mon Jan 24
14:15:25 -0800 2011
Processing by AttachmentsController#upload as */*
Parameters:
{"_http_accept"=>"application/javascript",
"authenticity_token"=>"F1h9pvCZL9HUgTjwCIAMc%252BW1cYwx7eBOPwThHfbS5ZU
%253D",
"file"=>#<ActionDispatch::Http::UploadedFile:0x1076a6d48
@content_type="image/jpeg", @headers="Content-Disposition:
form-data;
name=\"file\"; filename=\"joecocker.jpg\"\r\nContent-Type:
image/jpeg\r
\n", @original_filename="joecocker.jpg",
@tempfile=#<File:/var/folders/
lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/RackMultipart20110124-12264-
rbtnth-0>>}
The issue I''m having is I''m unable to save the uploaded file
to
Paperclip.
I''ve ried:
@attachment = Attachment.create(:attachment =>
File.open(params[:file].tempfile.path))
@attachment = Attachment.create(:attachment =>
params[:file].tempfile.path)
And neither work. Paperclip inserts a file attachment name of
"RackMultipart20110124-12264-rbtnth-0"
Any ideas / suggestions on how to save the file to paperclip? thanks
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
David Kahn
2011-Jan-24 22:33 UTC
Re: Rails Accessing an Uploaded File and Saving it to PaperClip
On Mon, Jan 24, 2011 at 4:22 PM, CuriousNewbie <bhellman1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, I''m using the following file uploader with Rails 3: > https://github.com/blueimp/jQuery-File-Upload > > The uploader on the client side is working fine. I can see in the > Rails log file that the following is being posted when I upload a > file: > > > Started POST "/attachments/upload" for 127.0.0.1 at Mon Jan 24 > 14:15:25 -0800 2011 > Processing by AttachmentsController#upload as */* > Parameters: {"_http_accept"=>"application/javascript", > "authenticity_token"=>"F1h9pvCZL9HUgTjwCIAMc%252BW1cYwx7eBOPwThHfbS5ZU > %253D", "file"=>#<ActionDispatch::Http::UploadedFile:0x1076a6d48 > @content_type="image/jpeg", @headers="Content-Disposition: form-data; > name=\"file\"; filename=\"joecocker.jpg\"\r\nContent-Type: image/jpeg\r > \n", @original_filename="joecocker.jpg", @tempfile=#<File:/var/folders/ > lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/RackMultipart20110124-12264- > rbtnth-0>>} > > The issue I''m having is I''m unable to save the uploaded file to > Paperclip. > > I''ve ried: > > @attachment = Attachment.create(:attachment => > File.open(params[:file].tempfile.path)) > @attachment = Attachment.create(:attachment => > params[:file].tempfile.path) >It should happen almost automatically. Make sure: Model: has_attached_file :attachment View -- make sure multipart: <%= form_for(@attachment, :html => { :multipart => true }) do |f| %> Controller -- should be business as usual -- @attachment = Attachment.new(params[:billing_run])> > And neither work. Paperclip inserts a file attachment name of > "RackMultipart20110124-12264-rbtnth-0" > > Any ideas / suggestions on how to save the file to paperclip? thanks > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.