0
votes

I have audio files located on a private GCS bucket. I want to serve these audio files for users to listen to.

I cant use Active Storage for this as these files are created/deleted outside of my Rails application.

I could download files using google-cloud-storage gem. It would cover authentication, file download. But if I understand correctly I can only serve files from the public directory? So do I need to download those to Rails.public_path?

Furthermore, I really don't want to manage these files after downloading them - caching, deleting them after some time, etc.

What would be the best way to achieve this?

1

1 Answers

0
votes

The best option in my opinion would be to use the google-cloud-storage gem, since both Google::Cloud::Storage::Bucket and Google::Cloud::Storage::File have the #signed_url method. This way you can find the relevant file(s) that you need and create a temporary url, send the url to the client, which will be in charge of downloading the file directly.

If you don't want the client do download the file directly from Google Cloud you can just download the file from GC yourself, and use #send_data or #send_file in the controller.