I am reading some zip file from disk through a rails application and sending it to another rails application, so in the receiver side the value of params["file"] is
#<ActionDispatch::Http::UploadedFile:0x00000008d66bb0
@content_type="application/zip",
@headers=
"Content-Disposition: form-data; name=\"file\"; filename=\"test.zip\"\r\nContent-Length: 2706\r\nContent-Type: application/zip\r\nContent-Transfer-Encoding: binary\r\n",
@original_filename="test.zip",
@tempfile=#<File:/tmp/RackMultipart20141221-3194-1cq6k5b>>
I want to download this zipped file to receiver disk, so I guess I need read its data and write it, so I do the fllowing:
File.open("filepath", "w") do |f|
f.write(params["file"].tempfile.read)
end
however I get the error message
Encoding::UndefinedConversionError ("\xF4" from ASCII-8BIT to UTF-8)
I tried several solutions to this encoding issue, but all in vain.
So how can I download a received zip file ? Thanks
Try:
File.open("filepath", "wb") do |f|
f.write(params["file"].tempfile.read)
end
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments