question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Update generate-thumbnail example because file.getSignedURL() does not work in the Cloud Functions environment

See original GitHub issue

How to reproduce these conditions

Sample name or URL where you found the bug https://github.com/firebase/functions-samples/blob/master/generate-thumbnail/functions/index.js Failing Function code used (including require/import commands at the top)

Steps to set up and reproduce This is the part that need to be updated to avoid the error. const config = { action: 'read', expires: '03-01-2500', }; const results = await Promise.all([ thumbFile.getSignedUrl(config), file.getSignedUrl(config), ]);

Debug output

Errors in the console logs

Error: The caller does not have permission at Gaxios._request (/workspace/node_modules/gaxios/build/src/gaxios.js:89:23) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async Compute.requestAsync (/workspace/node_modules/@google-cloud/common/node_modules/google-auth-library/build/src/auth/oauth2client.js:343:18) at async GoogleAuth.sign (/workspace/node_modules/@google-cloud/common/node_modules/google-auth-library/build/src/auth/googleauth.js:573:21) at async sign (/workspace/node_modules/@google-cloud/storage/build/src/signer.js:91:35)

Error: Process exited with code 16 at process.<anonymous> (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:271:38) at process.emit (events.js:315:20) at process.EventEmitter.emit (domain.js:483:12) at process.exit (internal/process/per_thread.js:167:15) at Object.logAndSendError (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/logger.js:37:9) at process.<anonymous> (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:268:22) at process.emit (events.js:315:20) at process.EventEmitter.emit (domain.js:483:12) at processPromiseRejections (internal/process/promises.js:209:33) at processTicksAndRejections (internal/process/task_queues.js:98:32) Screenshots

Expected behavior

When it calls file.getSignedUrl() it should retrieve a temporary url to download the new file.

Actual behavior

There is an error indicating that the caller does not have permission, inspecting the documentation of the cloud storage library for node in https://googleapis.dev/nodejs/storage/latest/File.html#getSignedUrl it says that in GCP environmets like Cloud Functions the signBlob API should be used. I think that the example should be updated to use this API.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:6

github_iconTop GitHub Comments

32reactions
leechycommented, Nov 6, 2020

Just follow the instructions in the README, and this error will gone:

Go to your project’s Cloud Console > IAM & admin > IAM, Find the App Engine default service account and add the Service Account Token Creator role to that member. This will allow your app to create signed public URLs to the images.

2reactions
fchabouiscommented, Jan 7, 2022

And if there are French speaking person here, Service Account Token Creator is “Créateur de jetons du compte de service”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why can't javascript not register getSignedUrl() (cloud ...
I'm not sure what you mean by register but using a forEach loop inside of Promise.all() won't form an array. So the problem...
Read more >
Troubleshooting Cloud Functions - Google Cloud
This document shows you some of the common problems you might run into and how to deal ... Error: please examine your function...
Read more >
getSignedUrl giving "SigningError: Failure from metadata server"
I solved it by adding "Cloud Functions Service Agent" role to my "App Engine default service account" service account.
Read more >
Firebase Functions Image Resizing | sdust - a Blog by Eric
Automatically resize your image on Firebase to generate thumbnail.
Read more >
Getting started with Cloud Functions (2nd gen)
In this codelab, you will learn about Google Cloud Functions (2nd gen). More specifically, you will deploy functions that respond to HTTP ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found