Active Storage Amazon S3
Chào các anh , Em đang có một vấn đề cần tham khảo mong anh chị giúp đỡ ạ.
Vấn đề
Em đang dùng Active Storage để upload ảnh lên trên S3. Khi em lấy link ảnh thì lấy theo kiểu "attachment.service_url". Mỗi lần lấy link ảnh thì link ảnh lại thay đổi,
Câu hỏi
Có cách này mà mình dựa vào cái key mà amazon cung cấp để mình có thể lấy link ảnh theo key đó mà link ảnh không thay đổi không ạ.
Em xin cảm ơn!
2 CÂU TRẢ LỜI
Bạn có thể làm thế này:
$ url_for(User.first.images.first)
=> http://localhost:3000/rails/active_storage/blobs/eyJfcmFpbHMiOn...
hoặc
rails_blob_url(User.first.images.first)
=> /rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJB...
để lấy link ảnh thông qua app, nó sẽ redirect về S3.
I've definitely been there with cloud storage and fluctuating URLs. It's frustrating when you need a persistent link for something like embedding an image in a document or presentation. I remember spending hours debugging a similar issue with a different cloud provider, trying to figure out the correct API endpoint and signature. Eventually, I ended up implementing a caching layer to store the signed URLs, which was a real headache. Dealing with temporary URLs can definitely eat up your time. If you're looking for a quick and relaxing way to unwind after wrestling with cloud storage, maybe give Tiny Fishing a try.