Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud Storage getting download link

I'm working in an Asp.Net Core 2 web api for files hosted at Google Cloud Storage. The files hosted there are not public, so I can't use the MediaLink property of the object. I tried to make a download endpoint using MemoryStream but when there are many users downloading large files at once I run into memory issues.

My question is: is there a way to create something link a one-time download link for a file or something similar?

I'm also trying to implement what's described in this link but I'd need to give the bearer token to the user. I can't do that.

Any tips?

like image 559
André Luiz Avatar asked Apr 25 '18 18:04

André Luiz


People also ask

Can you download directly to cloud storage?

How to Download File Directly to Online Storage Usually? For downloaing files to cloud storage, you can first of all download and save them to local disk and then upload them from local to cloud storage. As for downloading directly to cloud, you can turn to the third party tool such as MultCloud for help.

Can I upload files to Google Cloud Storage from URL?

Uploading files to Google Cloud Storage from a URL is possible, but there are a few things to keep in mind. First, you'll need to create a Google Cloud Storage bucket and give it a name. Next, you'll need to create a file object in the bucket and provide the URL of the file you want to upload.


1 Answers

Yes. Google Cloud Storage offers a feature called "signed URLs" that is what you described: a URL that is only good for a short while to download a single file. The idea is that you craft a download URL, then use the private key of a service account to "sign" the URL. Anyone holding that final URL can use it to act as that service account for the purpose of downloading that one object.

Take a look: https://cloud.google.com/storage/docs/access-control/#Signed-URLs

Writing code to generate the signed URL is a bit tricky, but the client libraries provide helper methods in several languages to do it for you. You can also generate one with the gsutil command: gsutil signurl -d 10m privatekey.p12 gs://bucket/foo

There is a code sample for generating he signed URLs programatically on their GitHub project: Signed URLs

like image 120
Brandon Yarbrough Avatar answered Oct 27 '22 01:10

Brandon Yarbrough