Ruby on rails Windows上的Rubyzip问题
我使用Rubyzip解压用户上传的文件。该文件包含一组图像,这些图像被解压缩并放入一个文件夹中。这在mac上运行良好,但在windows上它无法解压缩zip文件。以下是我使用的模型:Ruby on rails Windows上的Rubyzip问题,ruby-on-rails,windows,rubyzip,Ruby On Rails,Windows,Rubyzip,我使用Rubyzip解压用户上传的文件。该文件包含一组图像,这些图像被解压缩并放入一个文件夹中。这在mac上运行良好,但在windows上它无法解压缩zip文件。以下是我使用的模型: require "zip/zip" class Photo < ActiveRecord::Base validates_presence_of :image_file_name, :message => "Er is geen bestand bijgevoegd!" belongs_to
require "zip/zip"
class Photo < ActiveRecord::Base
validates_presence_of :image_file_name, :message => "Er is geen bestand bijgevoegd!"
belongs_to :album
has_attached_file :image, :styles => {
:original => ["1024x1024>", :jpg],
:medium => "300x250#",
:thumb => "150x100#"
}, :url => "/uploads/photos/:id/:style.:extension"
def zip?
image.content_type == "application/zip"
end
def save_photo
if zip?
extract_zip
true
else
self.save
end
end
def extract_zip
Zip::ZipFile.foreach(image.queued_for_write[:original].path) do |entry|
next if entry.name =~ /__MACOSX/ or entry.name =~ /\.DS_Store/ or !entry.file?
filename = entry.name
basename = File.basename(filename)
tempfile = Tempfile.new(basename)
tempfile.binmode
tempfile.write(entry.get_input_stream.read)
photo = Photo.create(:image => tempfile, :album_id => album_id)
end
end
end
需要“zip/zip”
类照片“Er是geen bestand bijgevoegd!”
属于:相册
已附加文件:图像,:样式=>{
:original=>[“1024x1024>”,:jpg],
:中等=>“300x250”,
:thumb=>“150x100#”
},:url=>“/uploads/photos/:id/:style.:extension”
def拉链?
image.content\u type==“应用程序/zip”
终止
def保存照片
如果拉链?
拔出拉链
符合事实的
其他的
自救
终止
终止
def提取拉链
Zip::ZipFile.foreach(image.queued_for_write[:original].path)do|entry|
如果entry.name=~/\u MACOSX/或entry.name=~/\.DS\u Store/或!entry.file?
filename=entry.name
basename=文件。basename(文件名)
tempfile=tempfile.new(basename)
tempfile.binmode
tempfile.write(entry.get\u input\u stream.read)
创建(:image=>tempfile,:album\u id=>album\u id)
终止
终止
终止
因为它在mac电脑上运行良好,我认为这是Windows压缩文件的方式。也许和标题结构有关,或者什么的?非常感谢您的帮助 这里有一条几年前的线索可能会有所帮助:Thanx!我来看看!