[Bug]: upload_options plugin moves file from store to cache
Faq opened this issue · comments
Report
Shrine.storages = {
cache: Shrine::Storage::FileSystem.new('public', prefix: 'uploads/cache'),
store: Shrine::Storage::FileSystem.new('public', prefix: 'uploads')
}
Shrine.plugin :activerecord
Shrine.plugin :cached_attachment_data # for retaining the cached file across form redisplays
Shrine.plugin :restore_cached_data # re-extract metadata when attaching a cached file
Shrine.plugin :validation # for filetype extension validation
Shrine.plugin :validation_helpers
Shrine.plugin :upload_options, cache: { move: true }, store: { move: true }
In attachment model is:
include Uploader::Attachment(:file)
There is need to attach copy of this uploaded file, from form called:
new(file: somefile.attachment.file
)
When set move:false
, in cache is crated new file and later saved in store, what is fine.
Problem is when is set move:true
.
Anyone encountered this? Is this expected behavior?
Expected Behavior
Original file not moved from store
storage, everything else works just fine.
Actual Behavior
The problem:
- while
cache: { move: true }
is set and copy of original file (by executingnew(file:
somefile.attachment.file)
) created incache
folder - original file from
store
is deleted (in db link to original file not cleared and pointing to not existing file)
Something similar was for copy plugin, mentioned in: https://discourse.shrinerb.com/t/duplicate-a-record-with-an-image/351
Steps to Reproduce the Problem
- Ruby code to demonstrate the problem.
Ruby Version
2.6
Shrine Version
3.2.1
Anything else?
No response
@Faq hey this is a great start. however, it looks like the full code sample has not been provided? (I'm having a little trouble understanding)
Edited post, with more accurate information, still no example yet.
Please produce a self-contained script that reproduces the problem, from what you posted I'm not able to see what the problem is.