Skip to content Skip to sidebar Skip to footer

How To Read File From @google-cloud/storage?

I am retriving a file from my bucket. I get the file and want to read it's contents but I do not want to download it to my local project i just want to read the contents, take the

Solution 1:

createReadStream is asynchronous and returns immediately. You have to use the callbacks to find out when the download to memory is complete. Right now, your code is always going to print "data undefined" because it's trying to print the response before it's available.

createReadStream is definitely the right way to go, but you will have to understand how node streams work in order to process the results correctly. There is a whole section in the linked documentation for reading streams, which is what you want to do here. The way you deal with the stream is not specific to Cloud Storage - it's the same for all node streams.

You might be helped by the answers to these questions that deal with reading node streams:

Post a Comment for "How To Read File From @google-cloud/storage?"