Skip to content

Instantly share code, notes, and snippets.

@stephenplusplus
Created May 6, 2019 17:58
Show Gist options
  • Select an option

  • Save stephenplusplus/82ad8615b7a7461c2426b7f33f9ae164 to your computer and use it in GitHub Desktop.

Select an option

Save stephenplusplus/82ad8615b7a7461c2426b7f33f9ae164 to your computer and use it in GitHub Desktop.

Revisions

  1. stephenplusplus created this gist May 6, 2019.
    26 changes: 26 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    '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)
    12 changes: 12 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    {
    "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"
    }
    }
    1 change: 1 addition & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    https://github.com/googleapis/nodejs-storage/issues/674