blueether
blueether

Reputation: 3966

Can I fire Google Cloud Storage event triggers manually?

Due to some changes I made recently, I'd like to be able to re-generate thumbnails for files in my storage bucket so that onFinalize gets called and regenerates thumbnails and some metadata.

Is there a way to do this, either from the commandline or through code?

Upvotes: 2

Views: 525

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598817

There is no built-in "retrigger all files" functionality in Cloud Functions.

As Doug commented, one option is to rewrite all files.

Alternative I'd create a HTTPS triggered function that calls the same code as the Storage trigger does, and then invoke that once.

So something like:

exports.generateThumbnail = functions.storage.object().onFinalize((object) => {
  _generateThumbnail(object.name);
});

exports.regenerateAllThumbnails = functions.https.onRequest((req, res) => {
  ["folder/file1.jpg", "folder/file2.jpg"].forEach(name => {
    _generateThumbnail(name);
  })
});
function _generateThumbnail(name) {
  ...
}

Upvotes: 2

Related Questions