Skip to content

Instantly share code, notes, and snippets.

@e-lin
Created June 26, 2019 04:02
Show Gist options
  • Select an option

  • Save e-lin/207c4962569a7d1774088225da00de45 to your computer and use it in GitHub Desktop.

Select an option

Save e-lin/207c4962569a7d1774088225da00de45 to your computer and use it in GitHub Desktop.
Storage upload trigger 1 - add document to Firestore
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