Created
June 26, 2019 04:02
-
-
Save e-lin/207c4962569a7d1774088225da00de45 to your computer and use it in GitHub Desktop.
Storage upload trigger 1 - add document to Firestore
This file contains hidden or 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
| export const onPic = functions.storage.object().onFinalize(_onPic) | |
| async function _onPic(object: functions.storage.ObjectMetadata): Promise<any> { | |
| const path = object.name // "pictures/20180624120000.jpg" | |
| const id = basename(path, '.jpg') // "20180624120000" | |
| try { | |
| // add a document to Firestore with the details of this pic | |
| const pic: Pic = { | |
| id: id, | |
| date: new Date(), | |
| imagePath: path, | |
| } | |
| await firestore.collection('pics').doc(id).set(pic) | |
| // ... skip ... | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment