1

I am trying to use ActiveStorage to store my images. With Paperclip, in S3 bucket we can have product/id_image/*.png. But with ActiveStorage, all is at the root and in the variants folder.

Any way to implement hierarchy like behaviour while uploading file on S3 , at least one folder by model ?

Adelin
  • 6,791
  • 5
  • 33
  • 58
Olivier
  • 323
  • 2
  • 4
  • 14
  • Possible duplicate of [How to specify a prefix when uploading to S3 using activestorage's direct upload?](https://stackoverflow.com/questions/48389782/how-to-specify-a-prefix-when-uploading-to-s3-using-activestorages-direct-upload) – George Claghorn May 01 '18 at 22:23

1 Answers1

0

Active Storage by default doesn't contain a path/folder feature but you can override the function by

model.file.attach(key: "product/id_image/filename.png", io: File.open(file), content_type: file.content_type, filename: "#{file.original_filename}")

Doing this will store the key with the path where you want to store the file in the s3 subdirectory and upload it at the exact place where you wanted it in s3.

Dharman
  • 21,838
  • 18
  • 57
  • 107