← Back to Upcase

after_create / after_save and saving files [Paperclip]

(jon) #1

I’m working on a project that needs to accept file uploads. After the file is uploaded, I’m doing some processing - extracting information from the file. I eventually plan to run this in a background worker, but it’s currently running inline.

I’ve tried making use of both after_create and after_save to process the file, but it seems it’s not saved at that point - so my tests fail with “No such file or directory”.

Is there any way to trigger the save method early, or to somehow run my method after the file has been saved to the file system?

(jon) #2

I’ve tried after_post_process as well, but it seems the file still isn’t saved at the point of calling my method.

I still end up with no such file or directory. Removing the post process callback works as expected - the file is saved and my extra work isn’t ran.

Edit: Scratch that, I didn’t get it. Still “file not found”.

(jon) #3

I was able to run my method from after_commit, and I found that the file was saved before the method ran.

Is there a better way to do it, or is after_commit an acceptable way?