Giter VIP home page Giter VIP logo

Comments (3)

amsdamsgram avatar amsdamsgram commented on July 25, 2024

Hi,

After digging a little bit, it seems that functions.storage.object().onChange(event is causing the infinite loop.
Since it is listening to all changes of the storage and our function is uploading a new image at the end. It probably triggers an onchange event and here we go again?

EDIT: I did a small trick, it's not clean but it stops the infinite loop waiting for a better fix.
I've added optimized: true in the metadata:

    // Uploading the Blurred image.
    metadata.blurred: true;
    return bucket.upload(tempLocalFile, {
      destination: filePath,
      metadata: {metadata: metadata} // Keeping custom metadata.
    });

And then I checked on the onChange(event) if the image is already blurred or not:

if (object.metadata.blurred) {
    return console.log("Already blurred");
  }

Works fine, I have a log "Already blurred" and then it stops.

from functions-samples.

nicolasgarnier avatar nicolasgarnier commented on July 25, 2024

The trick is nice indeed :) (good way to use metadatas)

But normally the function does not run in a loop. The issue is that in your code it seems you have removed the Cloud Vision API call (this is what stops the loop) and you are always blurring the image (you were just testing this I guess).

In the original sample we first check if the image is offensive and, if it is, we blur it. The function gets called again on the new blurred image but - because it's been blurred - the image is not detected as being offensive on the second check and this ends the loop.

By the way be careful when using metadata because the users can set them from the client (when you upload the image) and they could use that to bypass the image check on the function. You can avoid that by using some special security rules to forbid setting the metadata from the client though.

from functions-samples.

amsdamsgram avatar amsdamsgram commented on July 25, 2024

Thanks for your tips! I was not aware of metadata risk :)

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.