How to copy files without deleting the original file?

Hi, shrine 2.x used to have a copy plugin. According to the changelog you can now do the following to achieve the same thing:

attacher.attach other_attacher.file
attacher.add_derivatives other_attacher.derivatives # if using derivatives

I think the docs are wrong here. If i use the provided code then the original file is deleted after saving the model. How can i keep the original file? I want to create a copy instead of moving the file.

You should be able to do it by using Attacher#upload and Attacher#set, which won’t schedule the previous file for deletion:

attacher.set attacher.upload(other_attacher.file)
attacher.add_derivatives other_attacher.derivatives # if using derivatives

You’re right that the copy plugin didn’t replace the previous file, we should probably update the upgrading guide with this code.

1 Like

Thanks! The provided code works as expected.