Created
July 16, 2018 18:59
-
-
Save xrd/0bca1c8cbd17be97c7ebd796dc6e0892 to your computer and use it in GitHub Desktop.
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
const functions = require('firebase-functions'); | |
const os = require('os'); | |
const fs = require('fs'); | |
const path = require('path'); | |
const admin = require('firebase-admin'); | |
admin.initializeApp(); | |
exports.testItOut = functions.firestore | |
.document('blarg/{docId}') | |
.onUpdate((change, context) => { | |
console.log( "Inside #testItOut" ); | |
const storage = admin.storage() | |
let bucketName = 'signatures'; | |
let fileName = 'temp.txt'; | |
const tempFilePath = path.join(os.tmpdir(), fileName); | |
console.log( `Writing out to ${tempFilePath}` ); | |
fs.writeFileSync(tempFilePath, "something!" ); | |
return storage | |
.bucket( bucketName ) | |
.upload( tempFilePath ) | |
.then( () => fs.unlinkSync(tempFilePath) ) | |
.catch(err => console.error('ERROR inside upload: ', err) ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment