Reputation: 109
I've created an unzip onFinalize function, which unzip any file which copied to storage, then delete the file, which is working well, but I want to get return from the onFinalize cloud function to my Angular app, or listening somehow to know when finished the process.
Now I use logging, but its annoying, because the rest call to logger api use the accessToken, and its impossible to refresh the accessToken after expired in 3600s (only if the user logout, and login again its counting again)
Anyway is there a good solution in Angular without rest call, or without access token?
export const manageZipArchives = functions
.region("xxxxx")
.runWith({timeoutSeconds: 540, memory: "512MB"})
.storage.bucket("xxxxxxxxx")
.object()
.onFinalize(async (obj: functions.storage.ObjectMetadata) => {
const file = admin
.storage()
.bucket(obj.bucket)
.file(obj.name!);
...
return ok;
});
Upvotes: 0
Views: 261
Reputation: 83103
It's very strange, that I can't listening, or get return from function (from your comments)
Cloud Functions triggered by Cloud Storage events are background Cloud Functions. They don't have any notion of a client (or a frontend): the file created in Cloud Storage could have been created by a backend process, like an app running on a Compute Engine instance for example.
In your case, you can get advantage of the realtime listeners offered by either Firestore or the Realtime Database.
Let's take the example of a Firestore document. The process would be as follows:
In your Angular app:
doc()
method, in a specific collection.id
property.onSnapshot()
method. The doc does not exist yet, but this is not a problem: when it will be created the listener will be fired.In your Cloud Function:
Note that if you want to report a potential error or exception to the frontend you could also use the Firestore doc: for example you can add a status
field and an errorMessage
field with the desired info. In the listener you'll get the value of those fields.
Upvotes: 1