Yêu cầu thg 4 24, 2019 10:24 SA 191 1 2
  • 191 1 2
+1

Active Storage Amazon S3

Chia sẻ
  • 191 1 2

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


Đã trả lời thg 4 25, 2019 1:01 SA
+1

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.

Chia sẻ
Đã trả lời thg 3 17, 4:19 SA
0

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.

Chia sẻ
Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí