Created
November 30, 2018 15:58
-
-
Save jefBinomed/d130c490e663bf998d57f837c283d8fb to your computer and use it in GitHub Desktop.
2018-countdown-cloudfunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Method trigger when an image is upload | |
*/ | |
exports.detectImage = functions.storage.object().onChange(event => { | |
const object = event.data; // The Storage object. | |
const fileBucket = object.bucket; // The Storage bucket that contains the file. | |
const filePath = object.name; // File path in the bucket. | |
const contentType = object.contentType; // File content type. | |
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. | |
... | |
try { | |
const userId = path.dirname(filePath).split(path.sep).pop(); | |
const drawId = path.basename(filePath, '.jpg'); | |
return prediction.predictPromise(event) | |
.then((result) => { | |
console.log('Got result for drawId : ' + drawId); | |
return updateTree(userId, drawId, result); | |
}) | |
.catch((err) => { | |
console.log('Error trapped !'); | |
console.error(err); | |
return updateTree(userId, drawId); | |
});; | |
} catch (e) { | |
console.log('Error trapped by catch !'); | |
console.error(e); | |
} | |
return; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment