Giter VIP home page Giter VIP logo

Comments (21)

aldoromo88 avatar aldoromo88 commented on July 25, 2024 2

I was having the same problem.
Apparently it is caused by missing permission on service account executing cloud function.

I just added Storage Object Admin role to default to default service account and everything start to work as expected.
image

from functions-samples.

inlined avatar inlined commented on July 25, 2024 1

For posterity: Cloud Functions requires editor permission on your project.

from functions-samples.

nicolasgarnier avatar nicolasgarnier commented on July 25, 2024 1

FYI this issue is somewhat widespread because we used to have a bug (as of 1-2 month ago) where lots of Cloud Storage Buckets were created with the wrong permissions. New projects don't have this issue but if you have an old Firebase project which is impacted by this the manual fix for your permissions is described here:

firebase/codelab-friendlychat-web#184 (comment)

from functions-samples.

nicolasgarnier avatar nicolasgarnier commented on July 25, 2024

Can you tell us a bit more about when the deploy error happens? Is that when you are running the CLI firebase deploy? Can you copy paste the full output off the CLI?

from functions-samples.

amitava82 avatar amitava82 commented on July 25, 2024

Exactly, during deployment process. I've searching more about this, and it seems we need to have billing enabled and firebase store and google cloud store are two different products. My understanding was that the image resizing function works on firebase store which apparently is not correct. My use case is, when someone uploads file to firebase store (using firebase client) I want to resize image using cloud function. Could you please clarify if that's possible?

i  deploying functions
i  functions: ensuring necessary APIs are enabled...
i  runtimeconfig: ensuring necessary APIs are enabled...
✔  runtimeconfig: all necessary APIs are enabled
✔  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (2.63 KB) for uploading
✔  functions: functions folder uploaded successfully
i  starting release process (may take several minutes)...
i  functions: updating function addTag...
i  functions: updating function adjustments...
i  functions: updating function generateThumbnail...
⚠  functions[generateThumbnail]: Deploy Error: Failed to configure trigger GCS Bucket: product_images
✔  functions[addTag]: Successful update operation.
✔  functions[adjustments]: Successful update operation.
✔  functions: 2 function(s) deployed successfully.

from functions-samples.

nicolasgarnier avatar nicolasgarnier commented on July 25, 2024

Can you change:

exports.generateThumbnail = functions.storage.bucket().object().onChange(event => {

to:

exports.generateThumbnail = functions.storage.object().onChange(event => {

?

It looks like Functions thinks you want a trigger on the bucket named product_images which would happened if your code was:

exports.generateThumbnail = functions.storage.bucket('product_images').object().onChange(event => {

Even if that works, could you paste what you have in your code above so we can investigate?

from functions-samples.

amitava82 avatar amitava82 commented on July 25, 2024

This is what I have, same as you suggested.

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const gcs = require('@google-cloud/storage')();
const spawn = require('child-process-promise').spawn;

exports.generateThumbnail = functions.storage.object().onChange(event => {
  const object = event.data;
  const fileBucket = object.bucket;
  const filePath = object.name;
  const contentType = object.contentType;
  const resourceState = object.resourceState;

  if(!filePath.match(/product_images/)) {
    console.log('not product_images bucket');
    return;
  }

  if (!contentType.startsWith('image/')) {
    console.log('This is not an image.');
    return;
  }

  const fileName = filePath.split('/').pop();
  // Exit if the image is already a thumbnail.
  if (fileName.startsWith('thumb_')) {
    console.log('Already a Thumbnail.');
    return;
  }

  if (resourceState === 'not_exists') {
    console.log('This is a deletion event.');
    return;
  }

  const bucket = gcs.bucket(fileBucket);
  const tempFilePath = `/tmp/${fileName}`;

  return bucket.file(filePath).download({
    destination: tempFilePath
  }).then(() => {
    console.log('Image downloaded locally to', tempFilePath);
    // Generate a thumbnail using ImageMagick.
    return spawn('convert', [tempFilePath, '-thumbnail', '64x64>', tempFilePath]).then(() => {
      console.log('Thumbnail created at', tempFilePath);
      // We add a 'thumb_' prefix to thumbnails file name. That's where we'll upload the thumbnail.
      const thumbFilePath = filePath.replace(/(\/)?([^\/]*)$/, `$1thumb_$2`);
      // Uploading the thumbnail.
      return bucket.upload(tempFilePath, {
        destination: thumbFilePath
      });
    });
  });
});

from functions-samples.

inlined avatar inlined commented on July 25, 2024

This looks like it's a backend issue. I can investigate; do we have permission to view logs related to your account?

from functions-samples.

amitava82 avatar amitava82 commented on July 25, 2024

@inlined Sure! Let me know if anything is required.

from functions-samples.

inlined avatar inlined commented on July 25, 2024

I found a stack trace in our backend; since this conversation includes details about your personal app I'm going to reach out to you at the email address listed on your GitHub profile.

from functions-samples.

amitava82 avatar amitava82 commented on July 25, 2024

Yes @inlined mailed me with details. I'm guessing the particular project I was working on was affected by the bug. It worked fine with a new project.

from functions-samples.

nicolasgarnier avatar nicolasgarnier commented on July 25, 2024

Glak you got it sorted @amitava82 !

I'm changing the title and added the comment above so that it's easier to find for other developers that might be infected.

from functions-samples.

carllippert avatar carllippert commented on July 25, 2024

Just had this happen with a Realtime Database trigger for firebase. Should I report as bug? Trigger has not been edited and has worked previously.

from functions-samples.

inlined avatar inlined commented on July 25, 2024

Please contact support directly. GitHub bugs are for bugs with the SDK.

from functions-samples.

shadow1349 avatar shadow1349 commented on July 25, 2024

@inlined I am getting this exact same issue. Would you mind having a look for me?

https://stackoverflow.com/questions/48901888/firebase-storage-trigger-not-working

from functions-samples.

PierBover avatar PierBover commented on July 25, 2024

I'm having the same issue.

I'm deploying a function and getting Failed to configure trigger GCS Bucket.

I'm declaring the function as required per the docs:

functions.storage.object().onFinalize((object) => {...})

This exact same function deploys ok on another project.

Edit:
I've created a new Firebase project and tried to deploy with the same error.

I've contacted Firebase support but I need to solve this ASAP and these guys are usually quite slow.

from functions-samples.

clement89 avatar clement89 commented on July 25, 2024

I have added permission but still not working for me

from functions-samples.

peterwarbo avatar peterwarbo commented on July 25, 2024

I started receiving these messages as well with a newly created firebase project. It was working previously with my old project.

from functions-samples.

mparpaillon avatar mparpaillon commented on July 25, 2024

Same for me. I've tried everything I could find online (changing IAM, adding roles, updating permissions...) but the deploy won't work. Even with a new project. My other project (created a year ago) works fine though...

from functions-samples.

mparpaillon avatar mparpaillon commented on July 25, 2024

@peterwarbo I haven't changed a thing and now it works for me. Could you try again ?

from functions-samples.

peterwarbo avatar peterwarbo commented on July 25, 2024

@mparpaillon ah, will try again. Maybe it was a temporary outage with storage 😊

from functions-samples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.