Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming file before saving in ActiveStorage - Rails 5.2

I'm trying to rename a user uploaded file before saving in ActiveStorage and I don't seem to find any docs to do that. Hopefully someone has successfully done it and has code examples to share.

Thank you.

like image 210
Chong Hui Avatar asked Aug 31 '25 02:08

Chong Hui


1 Answers

You can try the following method

@message.image.attach(io: File.open('/path/to/file'), filename: 'file.pdf')

in the official ActiveStorage documentation you can find more examples

like image 54
Andres23Ramirez Avatar answered Sep 02 '25 15:09

Andres23Ramirez