Last active
August 13, 2016 23:58
-
-
Save farmisen/0b7aa7a762037ddd453cc62178b9b5aa to your computer and use it in GitHub Desktop.
upload file to gcloud
This file contains 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
// Install the gcloud CLI from https://cloud.google.com/sdk/downloads | |
// then login by doing gcloud auth login [email protected] | |
import fs from 'fs' | |
... | |
.use('/test', async(ctx, next) => { | |
console.log("IN TEST!") | |
const CLOUD_BUCKET = 'occamzrazor'; | |
const storage = gcloud.storage({ | |
projectId: 'occamz-staging' | |
}); | |
const bucket = storage.bucket(CLOUD_BUCKET); | |
const fileName = 'package.json' | |
const gcsname = Date.now() + '_' + fileName; | |
const file = bucket.file(gcsname); | |
const stream = file.createWriteStream(); | |
stream.on('error', function (err) { | |
console.log("ERROR:" + err) | |
next(err); | |
}); | |
stream.on('finish', function () { | |
console.log("GCSNAME:" + gcsname) | |
console.log("PUB URL:" + 'https://storage.googleapis.com/' + CLOUD_BUCKET + '/' + gcsname) | |
next(); | |
}); | |
stream.end(fs.readFileSync('./package.json')); | |
next(); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment