[英]How to write received zip file content using ruby on rails
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 我正在通过Rails应用程序从磁盘读取一些zip文件,并将其发送到另一个Rails应用程序,因此在接收器端,params [“ file”]的值为
#<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 ? 那么,如何下载收到的zip文件? Thanks
谢谢
Try: 尝试:
File.open("filepath", "wb") do |f|
f.write(params["file"].tempfile.read)
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.