Created
July 16, 2018 18:35
-
-
Save xrd/2d24016d16a7e12d7b280c56541af2d5 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'); | |
exports.testItOut = functions.firestore | |
.document('blarg/{docId}') | |
.onUpdate((change, context) => { | |
console.log( "Inside #testItOut" ); | |
const admin = require('firebase-admin'); | |
admin.initializeApp(); | |
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