It is possible to obtain a signed URL for images that are stored in Google Cloud Storage when using a Node.js server on Cloud Run.
To obtain a signed URL, you can use the Google Cloud Storage client library for Node.js. Here's an example:
const { Storage } = require('@google-cloud/storage');
// Creates a client
const storage = new Storage();
// Bucket name where the image is stored
const bucketName = 'my-bucket';
// Path to the image file
const filePath = 'path/to/image.png';
// Expiration time for the signed URL (in seconds)
const expiration = 300; // 5 minutes
// Generate a signed URL
const [url] = await storage.bucket(bucketName).file(filePath).getSignedUrl({
action: 'read',
expires: Date.now() + expiration * 1000, // convert expiration to milliseconds
});
// Use the signed URL to access the image
console.log(url); // e.g. https://storage.googleapis.com/my-bucket/path/to/image.png?Expires=xxxx&GoogleAccessId=xxxx&Signature=xxxx
Note that the signed URL is time-limited and can only be used for the specified action (in this case, "read"). You can also specify additional options such as headers and content type when generating the signed URL.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-05 11:21:52 +0000
Seen: 2 times
Last updated: Jun 05 '23
How can I deal with Expression.Error related to a column in Power Query?
How can you implement pagination in Oracle for the LISTAGG() function?
What is the process for implementing a FutureBuilder on an OnTap function in Flutter?
How can we require users to be logged in before they can access the root folders in WordPress?
In SCSS, what is the method for grouping and reusing a set of classes and styles?
How can popen() be used to direct streaming data to TAR?
How does iOS retrieve information from a BLE device?
How can Django Admin accommodate a variety of formats and locales for its input fields?