Skip to content
This repository has been archived by the owner on Oct 5, 2018. It is now read-only.

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

Closed
jaybloke opened this issue Oct 2, 2016 · 4 comments

Comments

@jaybloke
Copy link

jaybloke commented Oct 2, 2016

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
Copy link
Collaborator

morgoth commented Oct 2, 2016

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
Copy link
Author

jaybloke commented Oct 2, 2016

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
Copy link
Collaborator

morgoth commented Oct 2, 2016

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
Copy link
Author

jaybloke commented Oct 2, 2016

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

Cheers!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants