Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paperclip rename uploaded files by user

Is it possible to allow the user to rename the uploaded file?

If there is a share link, will it be automatically updated. I am not able to do this since i cant first figure out how to rename the file.

like image 858
arjun Avatar asked Jan 22 '26 12:01

arjun


1 Answers

You can rename the files and then change the record file name. For instance, based on this answer, you can do:

(record.image.styles.keys+[:original]).each do |style|
    path = record.image.path(style)
    FileUtils.move(path, File.join(File.dirname(path), new_file_name))
end

record.image_file_name = new_file_name
record.save

If you're using Amazon S3, you can do:

AWS::S3::S3Object.move_to record.image.path(style), new_file_path, record.image.bucket_name

Check this out: Paperclip renaming files after they're saved

like image 98
Sergio A. Avatar answered Jan 25 '26 05:01

Sergio A.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!