jrgifford / delayed_paperclip

Process your Paperclip attachments in the background with delayed_job or Resque.
http://www.jstorimer.com/ruby/2010/01/30/delayed-paperclip.html
MIT License
404 stars 155 forks source link

Not saving original file - only those styles specified in only_process are created #199

Closed jaybloke closed 8 years ago

jaybloke commented 8 years ago

For some reason, the delayed_paperclip is not storing the original file... only the styles listed in the only_process array are created.

The delayed job subsequently fails for the other styles as it cannot find the original file...

Errno::ENOENT: No such file or directory @ rb_sysopen - /Users/Home/Dev/app/public/system/images/project_photographs/images/000/000/400/d275126025f8f2ca44c7685dc36b4614058765f7.jpg

Looks like a bug using Paperclip 5.1.0 and Delayed Paperclip 3.0.1. Downgraded to Paperclip 5.0.0 and Delayed Paperclip 3.0.0 and all works fine.

Currently using:

Rails 4.2.7.1 Delayed Paperclip 3.0.1 Paperclip 5.1.0 Sidekiq 4.2.2

Model:

class ProjectPhotograph < ActiveRecord::Base

  # uses image_processing boolean column

  has_attached_file :image,

    styles: {

      small: {
        geometry: '300x200#',
        format: :jpg
      },

      small_webp: {
        geometry: '600x400#',
        format: :webp
      },

      medium: {
        geometry: '900x600#',
        format: :jpg
      },

      medium_webp: {
        geometry: '900x600#',
        format: :webp
      }

    },

    only_process: [:small, :small_webp]

  process_in_background :image, only_process: [:medium, :medium_webp], processing_image_url: :processing_image_fallback

  def processing_image_fallback
    options = image.options
    options[:interpolator].interpolate(options[:url], image, :small)
  end

end

Controller action:


# Load object from S3 and attach to model

def create

    s3_object = S3Bucket.object(File.join(Settings.s3.upload_folder, uuid_param))

    photograph = ProjectPhotograph.new
    photograph.image = s3_object.get.body
    photograph.image_file_name = "#{uuid_param}#{Rack::Mime::MIME_TYPES.invert[s3_object.content_type] || '.jpg'}"

    if photograph.save
      render json: Api::V1::Member::Wizard::PhotographSerializer.new(photograph)
    else
      flash.now[:error] = 'Problem uploading photograph'
      render json: { errors: photograph.errors.messages }, status: :unprocessable_entity
    end

end

development.rb

  config.paperclip_defaults = {
    url: '/system/images/:class/:attachment/:id_partition/:hash.:extension',
    hash_data: ':class/:attachment/:id/:size/:updated_at',
    use_timestamp: false
  }
morgoth commented 8 years ago

Are you sure that this is delayed_paperclip issue? It may be related to https://github.com/thoughtbot/paperclip/pull/1993/files When you disable background processing, is the original file stored?

jaybloke commented 8 years ago

I can confirm that when background processing is disabled and only_process: [:small, :small_webp] is present on the model, the original file is not stored... however, the two :small and :small_webp styles are created.

morgoth commented 8 years ago

Then I would look into paperclip codebase and eventually open an issue there. I'm pretty sure it was introduced in https://github.com/thoughtbot/paperclip/pull/1993/files

jaybloke commented 8 years ago

Thanks @morgoth for the pointers. I will take a look at the code.

Cheers!