3

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.

arjun
  • 1,594
  • 16
  • 33

1 Answers1

8

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

Community
  • 1
  • 1
S. A.
  • 3,714
  • 2
  • 20
  • 31