1

我有这个动作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文件确实存在......我在这里做错了什么?

4

1 回答 1

4

您不能像那样直接使用 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
于 2013-09-20T15:46:43.890 回答