3

I'm setting up the env for local development and just testing to see if the emulators are working but my simple test is failing without any errors.

// functions/index.js
exports.pdftoimg = functions.storage.object().onFinalize(async (object) => {
  console.log({ object });
});

Emulators start without issues:

firebase emulators:start
i  emulators: Starting emulators: auth, functions, firestore, hosting, pubsub, storage
✔  functions: Using node@16 from host.
i  hosting: Serving hosting files from: dist
✔  hosting: Local server: http://localhost:5002
i  functions: Watching "/Users/xxx/Code/myApp/functions" for Cloud Functions...
✔  functions[us-central1-pdftoimg]: storage function initialized.

┌─────────────────────────────────────────────────────────────┐
│ ✔  All emulators ready! It is now safe to connect your app. │
│ i  View Emulator UI at http://localhost:4000                │
└─────────────────────────────────────────────────────────────┘

But when I upload a test pdf file to storage emulator using the UI (http://localhost:4000/storage/default-bucket) nothing is displayed in the logs.

I tested the cloud triggers for Firestore Db but that seems to work though.

What am I missing?

Thanks

eozzy
  • 66,048
  • 104
  • 272
  • 428
  • If the emulator is just not working the way you expect, you should file a bug with repro instructions and logs on GitHub. https://github.com/firebase/firebase-tools – Doug Stevenson Jan 12 '22 at 19:26

1 Answers1

1

I can see you are Triggering a Cloud Function on Cloud Storage Changes that returns the uploaded object metadata.

However, this function does not upload the file:

onFinalize Sent when a new object (or a new generation of an existing object) is successfully created in the bucket. This includes copying or rewriting an existing object. A failed upload does not trigger this event.

In that case please follow the documentation provided to Upload Files. Finally, adding Error Handling to your code will help you the next time as in this case you have no logs or anything to debug the error.

Update:

This issue onFinalize trigger not working in emulator, that uses the same Cloud Functions with the same results. We have to wait for support on that.

After some research a colleague found this github issue that uses the same documentation and the same methods you are using. The first one describes how ‘onFinalize’ is triggered even on failed upload: and also redirects to the documentation that was mentioned above. In this case the function is triggered when it’s not supposed to, you can try executing it like this.

Alex
  • 778
  • 1
  • 15
  • 1
    Are you saying that uploading programatically instead of uploading via Web UI would trigger `onFinalize`? Sure, I can try that to confirm but if thats the case then its indeed a bug. It shouldn't matter *how* the object was created in the bucket. – eozzy Jan 13 '22 at 22:23
  • No, sorry. I meant that you might not be receiving the data correctly, and/or you are not using the correct upload method in case of any. I was not able to find any example on how to treat this data, but I linked the documentation of the object metadata, you might want to try to get only certain properties and see if it works, E.g.: `object.name`, `object.metadata`. I found another [question](https://stackoverflow.com/a/53181557/16938011) that might help. – Alex Jan 17 '22 at 18:55
  • @eozzy just wondering if you have already read the update in my answer and hoping you could provide some feedback. – Alex Jan 27 '22 at 00:07
  • 1
    this solved the issue for me: https://github.com/firebase/firebase-tools/issues/4014#issuecomment-1021609657 – eozzy Jan 28 '22 at 05:59
  • Great, if that link mentioned in my answer was useful, could you please consider upvoting my answer, as it could help future users that see this discussion? – Alex Jan 28 '22 at 15:06