Errors Attaching Tempfile to Email in Rails
The file has an @attachment file. From debugging:
"datafile"=>#<ActionDispatch::Http::UploadedFile:0x3eee9c0 @original_filename="filename.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"datafile\"; filename=\"filename.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:C:/Users/.../RackMultipart20121026-2452-g369hf>>, It has been uploaded via the user form.
I am trying to attach it to an email:
... attachments[@attachment.original_filename] = @attachment mail(:to => " email@email.com ", :subject => "test", :from => @fromaddress) Which mistakes:
undefined method `length 'for #
I also tried
attachments[@attachment.original_filename] = @attachment.tempfile Which mistakes:
undefined method `[]' for #<Tempfile:0x5629e48> @attachment.original_filename returns the correct file name ("filename.jpg" in the example)
Anything obvious?
If you did not save the downloaded file in some place, it is a little limited what you can do with it (for security reasons - you should check the download and then save the file).
But you must have a read file:
attachments[@attachment.original_filename] = @attachment.read Note. I have not tested this, maybe you need to read from @attachment.tempfile