我的photos_controller
中有这个动作
def open_my_zip
url = "http://www.vbaccelerator.com/home/VB/Code/vbMedia/Audio/Lossless_WAV_Compression/Sample_APE_File.zip"
Zip::File.open(url) do |zipfile|
zipfile.each do |file|
# do something with file
Rails.logger.debug "hi"
end
end
end
由于某种原因,我收到此错误
Zip::ZipError (File http://www.vbaccelerator.com/home/VB/Code/vbMedia/Audio/Lossless_WAV_Compression/Sample_APE_File.zip not found):
但是 zip 文件确实存在...我在这里做错了什么?
你不能像这样直接使用 URL。请尝试以下代码:
require 'open-uri'
url = "http://www.vbaccelerator.com/home/VB/Code/vbMedia/Audio/Lossless_WAV_Compression/Sample_APE_File.zip"
zipfilename = open(url)
Zip::ZipFile.open(zipfilename) do |zipfile|
end