Skip to content

Instantly share code, notes, and snippets.

@xrd
Created July 16, 2018 18:35
Show Gist options
  • Save xrd/2d24016d16a7e12d7b280c56541af2d5 to your computer and use it in GitHub Desktop.
Save xrd/2d24016d16a7e12d7b280c56541af2d5 to your computer and use it in GitHub Desktop.
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