Skip to content

Instantly share code, notes, and snippets.

@stephenplusplus
Created May 6, 2019 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenplusplus/82ad8615b7a7461c2426b7f33f9ae164 to your computer and use it in GitHub Desktop.
Save stephenplusplus/82ad8615b7a7461c2426b7f33f9ae164 to your computer and use it in GitHub Desktop.
@google-cloud/storage Issue 674
'use strict'
const fs = require('fs-extra')
const {Storage} = require('@google-cloud/storage')
const gcs = new Storage()
const bucket = gcs.bucket(process.env.BUCKET_NAME)
const tmpFilePath = './tmp-file'
const tmpItemFilePath = './tmp-item-file'
const filePath = 'gissue-674--file'
const itemFilePath = 'gissue-674--item'
const uploadTmpFilePromise = fs
.outputFile(tmpFilePath, 'tmp-file contents')
.then(() => bucket.upload(tmpFilePath, {destination: filePath}))
const uploadTmpItemFilePromise = fs
.outputFile(tmpItemFilePath, 'tmp-item-file contents')
.then(() => bucket.upload(tmpItemFilePath, {destination: itemFilePath}))
Promise
.all([uploadTmpFilePromise, uploadTmpItemFilePromise])
.then(() => bucket.file(itemFilePath).exists())
.then(() => console.log('done!'), console.error)
{
"name": "gissue-674",
"version": "1.0.0",
"description": "",
"main": "index.js",
"keywords": [],
"author": "",
"dependencies": {
"@google-cloud/storage": "^2.5.0",
"fs-extra": "^7.0.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment