Last active
January 25, 2018 22:59
-
-
Save mootrichard/4e78f6a55df10ff2b414617515b18990 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 fs = require('fs'); | |
const Storage = require('@google-cloud/storage'); | |
const BUCKET_NAME = ''; // This would actually have the name of our bucket | |
const storage = new Storage({ | |
projectId: '', // This should be your Google Cloud Project ID where you're deploying your function & have your bucket | |
keyFilename: './keyfile.json' | |
}); | |
exports.webhook = (request, response) => { | |
const data = JSON.stringify(request.body, null, 2); | |
const fileName = `/tmp/${request.body.location_id}_${request.body.entity_id}_${Date.now()}.json`; | |
fs.writeFileSync(fileName, data); | |
storage | |
.bucket(BUCKET_NAME) | |
.upload(`${fileName}`) | |
.then((success) => { | |
fs.unlink(fileName); | |
console.log(success); | |
response.status(200).send(); | |
}) | |
.catch((error) => { | |
fs.unlink(fileName); | |
console.log(error); | |
response.status(403).send(error); | |
}); | |
}; | |
exports.event = (event, callback) => { | |
callback(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment