Rails Access the downloaded file and save it in PaperClip

I am using the following file downloader with Rails 3: https://github.com/blueimp/jQuery-File-Upload

The user on the client side is working fine. In the Rails log file, I see that the following happens when the file is uploaded:

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>>}

I have a problem: I cannot save the downloaded file in Paperclip.

I drew:

@attachment = Attachment.create(:attachment => File.open(params[:file].tempfile.path))
@attachment = Attachment.create(:attachment => params[:file].tempfile.path)

And nobody is working. Paperclip inserts the name of the attached file "RackMultipart20110124-12264-rbtnth-0"

Any ideas / suggestions on how to save the file in paperclip? thank

+5
source share
3 answers

params[:file] . params[:file].tempfile.path. Paperclip File - .

+10

, . . . 777

-, . , paperclip, . , .

  • , has_attached_file: avatar
  • paperclip rails g paperclip " " ( .)
  • , ,     f.file_field: avatar
  • show/index image_tag: avatar.url(: small), , , ..

, .

+1

It's hard to say without seeing the model code, but based on what I see, I would try:

@attachment = Attachment.create(params[:file])
0
source

All Articles