Browse Source

Updating GCS quickstart to use metageneration attribute value for determining if file is new

master
Brendan G. Lim 8 years ago
committed by GitHub
parent
commit
13111b279c
  1. 8
      quickstarts/thumbnails/functions/index.js

8
quickstarts/thumbnails/functions/index.js

@ -36,6 +36,7 @@ exports.generateThumbnail = functions.storage.object().onChange(event => {
const filePath = object.name; // File path in the bucket. const filePath = object.name; // File path in the bucket.
const contentType = object.contentType; // File content type. const contentType = object.contentType; // File content type.
const resourceState = object.resourceState; // The resourceState is 'exists' or 'not_exists' (for file/folder deletions). const resourceState = object.resourceState; // The resourceState is 'exists' or 'not_exists' (for file/folder deletions).
const metageneration = object.metageneration; // Number of times metadata has been generated. New objects have a value of 1.
// [END eventAttributes] // [END eventAttributes]
// [START stopConditions] // [START stopConditions]
@ -58,6 +59,13 @@ exports.generateThumbnail = functions.storage.object().onChange(event => {
console.log('This is a deletion event.'); console.log('This is a deletion event.');
return; return;
} }
// Exit if file exists but is not new and is only being triggered
// because of a metadata change.
if (resourceState === 'exists' && metageneration > 1) {
console.log('This is a metadata change event.');
return;
}
// [END stopConditions] // [END stopConditions]
// [START thumbnailGeneration] // [START thumbnailGeneration]

Loading…
Cancel
Save