luan / carrierwave-ftp

Allows file upload using FTP for CarrierWave uploaders.
MIT License
82 stars 63 forks source link

Uploader `recreate_versions!` doesn't work #37

Open Owumaro opened 6 years ago

Owumaro commented 6 years ago

Hi

I'm using carrierwave-ftp 0.3.1 (with carrierwave 1.2.1) to manage some image uploads with versions. I changed the processing of a version and need to reprocess all the existing images. So I'm trying to use recreate_versions! on the uploader: https://github.com/carrierwaveuploader/carrierwave#recreating-versions

It throws a NameError:

> model.img.recreate_versions!
NameError: undefined local variable or method `file' for #<CarrierWave::Storage::FTP::File:0x00000006345c50>
    from /.../gems/carrierwave-ftp-0.3.1/lib/carrierwave/storage/ftp.rb:76:in `content_type'
    from /.../gems/carrierwave-1.2.1/lib/carrierwave/uploader/cache.rb:86:in `sanitized_file'
    from /.../gems/carrierwave-1.2.1/lib/carrierwave/uploader/cache.rb:118:in `cache!'
    from /.../gems/carrierwave-1.2.1/lib/carrierwave/uploader/versions.rb:227:in `recreate_versions!'

I found this wiki entry: https://github.com/carrierwaveuploader/carrierwave/wiki/How-to:-Recreate-and-reprocess-your-files-stored-on-fog Which explains that the base img must be cached to reprocess it. It seems like the carrierwave-ftp File class doesn't implement the required methods.

Calling cache_stored_file! on the uploader produces the same error as above.

Thanks !

Owumaro commented 6 years ago

After investigation, I managed to make it work by manually setting a content_type on the file of the uploader:

> model.img.file.content_type = ""
=> ""
> model.img.recreate_versions!
=> [:store_versions!]

Edit: this only works if the image is still in the carrierwave cache. Otherwise you get a CarrierWave::ProcessingError: identify /tmp/mini_magick20171016-15060-1icpymt.png failed with error.