Search code examples
ruby-on-railsrails-activestorageminio

Rails: getting plain text path to file uploaded to Minio


I have a Minio server where I upload files with ActiveStorage and it upsets me that I can't seem to get the "real" file name for my uploads, for instance if I upload "vader.jpg" I get this path:

image_tag user.avatar.variant(resize: "100x100")

http://minio:9000/railsappdevelopment/variants/VTPPGy7qnLPWHPATLbpfp6aq/2baa7301537de02528c8347e9137a2c84c36c385682e395ae23b967891ba9d8b?response-content-disposition=inline%3B%20filename%3D%22vader.jpg%22%3B%20filename%2A%3DUTF-8%27%27vader.jpg&response-content-type=image%2Fjpeg&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=root%2F20190628%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190628T133239Z&X-Amz-Expires=300&X-Amz-SignedHeaders=host&X-Amz-Signature=2b18863d1600f1e402f6b4582ee27cfe3f80532b2d0fb110ea0581557f6b5264

I don't want all that garbage, I don't want the URLs to expire, all I want is http://minio:9000/railsappdevelopment/id/vader.jpg

The buckets are public and read-only.

Anyone know how to get rid of them URL parameters?


Solution

  • Unfortunately this is how ActiveStorage works - it uses random ids as storage keys (=file names for minio), even without file extension, so for browsers to interpret image correctly content-type header should be provided to minio (usually it is inferred by file extension), also all requests to content are expected to be dynamic (with expiring links etc.)

    There were multiple requests in rails issues (for example #30431, #31419), but no positive reaction yet.

    So if your requirements to image hosting differ from these of basecamp (that are fullfilled by activestorage) - as of now you have to resort to some other libraries like shrine or a custom solution.