A simple in memory zipfile processing gem usefull for doing zip upload of images with e.g. carrierwave.
Add this line to your application's Gemfile:
gem 'carrierwave-zipline', :require => 'carrierwave/zipline'
And then execute:
$ bundle
Or install it yourself as:
$ gem install carrierwave-zipline
You can take the gem for at testdrive by running:
rake console
#and you can use FakeUpload
file = FakeUpload.new("spec/files/simple.zip")
Carrierwave::Zipline.process(file) {|f| puts f.original_filename}
Example:
#POST
def zip_file
gallery_id = params[:pictures][:gallery_id]
@gallery = Gallery.find(gallery_id)
authorize! :manage, @gallery
zip_file = params[:pictures][:zip]
require 'carrierwave/zipline'
count = Carrierwave::Zipline.process(zip_file) do |file|
if %w{jpg jpeg gif png}.include? file.ext
img = Picture.new({gallery_id: @gallery.id})
img.image= file
img.save
else
false
end
end
flash[:success] = t("zip_pic.success", count: count)
redirect_to gallery_pictures_path(@gallery)
end
- Fork it ( https://github.com/mkrogh/carrierwave-zipline/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request