问题描述: 用https://dn-ikcrm-files-dev.qbox.me/attachments/files/9/issues.csv 会报错:Zlib::BufError (buffer error)。 其他的不会。
代码如下,大神们可以 try 一下。
http_download_with_words('https://dn-ikcrm-files-dev.qbox.me/attachments/files/9/issues.csv', 'temp.csv')
def http_download_with_words(uri, filename)
bytes_total = nil
binding.pry
uri.open(
read_timeout: 500,
:content_length_proc => lambda{|content_length|
bytes_total = content_length},
:progress_proc => lambda{|bytes_transferred|
if bytes_total
# Print progress
print("\r#{bytes_transferred}/#{bytes_total}")
else
# We don’t know how much we get, so just print number
# of transferred bytes
print("\r#{bytes_transferred} (total size unknown)")
end
}
) do |file|
open filename, 'wb' do |io|
file.each_line do |line|
io.write line
end
end
end
end
自己想了一个解决方案:
file.write(curl #{attachment.file.url}
)
it is work!