I want to send any file to client on request, from google storage , but its downloading locally on server. I don't to download locally rather if any way I can send file to client directly.
Currently I am doing this way for download
def download_file(self, bucket, key, path_to_download):
bucket = gc_storage.storage_client.bucket(bucket)
blob = bucket.blob(key)
blob.download_to_filename(path_to_download)
I don't think there is an API method to load data from GCS to a generic third location, although some data transfer options exist for certain specific use cases.
As mentioned in the comments,
smart-open
could be an option here, provided you're willing to at least stream the data through your server. Perhaps something like this:Here I've written out the full machinery for doing this with a service account, on the assumption that you aren't authenticated by default. My understanding is that you may be able to remove most of that if your computer is already set up to connect to GCS with some default credentials:
Note also that I've written this as if you were transferring the file from one GCS bucket to another one - but this is actually one of those cases where there is a built-in API method to achieve the goal!
It sounds like what you actually want to do is pass on the data to a third party, so the inner
with
statement will need replacing with whatever implementation you are actually using.