0

In my case I need to read file/icon.png from cloud storage/bucket which is a token base URL/path. Token resides in header of request.

I tried to use fs.readFile('serverpath') but it gave back error as 'ENOENT' i.e. 'No such file or directory' is existed, but file is existed on that path. So are these methods are eligible to make calls and read files from server or they work only with static path, if that is so then in my case how to read file from cloud bucket/server.

Here i need to pass that file-path to UI, to show this icon.

2 Answers 2

2

Use this lib to handle GCS operations. https://www.npmjs.com/package/@google-cloud/storage

If you do need use fs, install https://cloud.google.com/storage/docs/gcs-fuse, mount bucket to your local filesystem, then use fs as you normally would.

Sign up to request clarification or add additional context in comments.

Comments

1

I would like to complement Cloud Ace's answer by saying that if you have Storage Object Admin permission you can make the URL of the image public and use it like any other public URL.

If you don't want to make the URL public you can get temporary access to the file by creating a signed URL.

Otherwise, you'll have to download the file using the GCS Node.js Client.

I posted this as an answer as it is quite long to be a comment.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.