delayed_paperclip icon indicating copy to clipboard operation
delayed_paperclip copied to clipboard

May not be handling hash properly?

Open hoopsho opened this issue 14 years ago • 14 comments

Using the following values for that attachment:

... :path => "/:view_key/:style/:hash", :use_timestamp => false, :hash_secret => "hash.secret", :hash_data => ":class/:attachment/:id/:style/:updated_at" ...

The process works, and the styles are generated on S3, but the hash is different. The image from paperclip/rails perspective thinks that it has a different path with a different hash than what is actually out on S3.

S3: /l3n08oq9wqo18wgq8454/post/d3610c38d4d3c9efc8fa3ad92bbebe0be2236d49

Rails/paperclip: /l3n08oq9wqo18wgq8454/post/75953d644e3684c584d25e401ee250b0ce36ca78

If I remove the hashed path requirements, the code works great and happily places the files out on S3 with the default pathing.

Thoughts as to what may be the problem with using a hashed path? Is it that the code is not interrogating the hash_data and hash_secret when creating the file out on s3? or perhaps a mismatch in using the updated_at field?

Thanks, Chris.

hoopsho avatar Aug 08 '11 06:08 hoopsho

Hey,

This could indeed be related to a date attribute being updated during the background processing. Maybe it also could have something to do with the url_with_processed method (https://github.com/jstorimer/delayed_paperclip/blob/master/lib/delayed_paperclip.rb#L120)

Could you verify any of these cases? I don't have much time this week to investigate, but could make some time if I know what to fix...

Bertg avatar Aug 08 '11 07:08 Bertg

I cannot figure it out. There has to be two updates happening to the model, one of them prior to uploading to S3 and hte other prior to saving the record the second time in the DB.

hoopsho avatar Aug 12 '11 15:08 hoopsho

Can you have a look at this issue: https://github.com/jstorimer/delayed_paperclip/issues/34

It describes issues with the url method, and how this can be fixed.

I'd like to know if reverting to the original url method works for you.

Bertg avatar Aug 25 '11 15:08 Bertg

My default config:
:path => "/:view_key/:style/:hash" :use_timestamp => false :hash_secret => SECRET_HASH :hash_data => ":class/:attachment/:id/:style/:updated_at"

I tried the following combinations:

url(:post) url(:post, true) url_with_processing(:post) url_with_processing(:post, true) url_without_processing(:post) url_without_processing(:post, true)

all of which provide a different url than what is actually uploaded to S3 during the DJ process.

So maybe i am not making the right changes, but it does not seem to change anything.

hoopsho avatar Aug 25 '11 16:08 hoopsho

Hi,

I was wondering if this problem still exists in the latest git HEAD version?

If not, could you try to use the ":url_with_processing => false" option, and see if that fixes your issue.

Bertg avatar Sep 18 '11 19:09 Bertg

Hey,

Yea, still the same issue. I tried pulling in your repo via git and configuring the image params with url_with_processing set to false... same problem as before. the image gets placed in a different location than the URL references.

hoopsho avatar Sep 19 '11 15:09 hoopsho

Sorry, but with the given information I can not help you out.

I've assigned this to jstorimer, hoping he can help you with this.

Bertg avatar Sep 19 '11 15:09 Bertg

I will gladly provide more information, just let me know what more is needed.

hoopsho avatar Sep 19 '11 15:09 hoopsho

The same problem here, using local storage in Dev.

Without /:hash/ it works fine.

Paperclip::Attachment.default_options.update({
  :url => "/system/images/:class/:id/:attachment/:style/:hash/:basename"
})

dalssoft avatar Dec 05 '11 23:12 dalssoft

Problem is still exists. The reason of it that worker is triggering save on model, and it updates updated_at field. :updated_at and :hash interpolators are related from the model updated_at attribute value.

dmitry avatar Apr 27 '15 18:04 dmitry

Fixed with hacking into the activerecord callback:

  before_save do
    if photo.job_is_processing
      write_attribute(:photo_updated_at, photo_updated_at_was)
    end
  end

dmitry avatar Apr 27 '15 22:04 dmitry

For me the fix was similar. I have the <attachment>_processing column setup

before_save do
  avatar_updated_at = avatar_updated_at_was if avatar_processing
end

coneybeare avatar Dec 25 '15 23:12 coneybeare

Having the same issue. dmitry's hack working good for now. Edit: Actually dmitry's hack is only keeping the filename in database same. The filename of the actual file is still different.

abrbhat avatar Feb 17 '16 05:02 abrbhat

@abrbhat I've switched to https://github.com/janko-m/shrine, more modular (easier to follow the code) and predictable behavior.

dmitry avatar Feb 17 '16 10:02 dmitry