How can I get permanent URL of images from Active Storage?

I'm using Google Cloud services to upload my image files. I need permanent url of images that I uploaded.

I use .service_url for getting URL of files but that links expires after 5 minutes. I try to set expires dates too long but it does not help. How can I fix this?

Upvotes: 2

Views: 1361

Answers (2)

I found the answer.

Setting public: true solves this issue in storages.yml

For more information: https://edgeguides.rubyonrails.org/active_storage_overview.html#public-access

Upvotes: 1

guillaume blaquiere
guillaume blaquiere

Reputation: 75745

If you want a permanent link without middleware (I mean a system which catch your request and generate a temporary link for download), you can play with ACL and have this 3 solutions:

  • If anonymous user can access to the objects, you can grant allUsers on your objects (or your bucket) to make it public.
  • If only unknown authenticated user can access to the object, you can grant allAuthenticated on your objects (or your bucket).
  • If only known authenticated user can access to the object, you can grant then individually on your objects (or your bucket).

In all cases, the objects are accessible through this url https://storage.googleapis.com/<bucket>/path/to/file

Upvotes: 1

Related Questions