Upload a file to Google Cloud, in a specific directory

前端 未结 6 1731
借酒劲吻你
借酒劲吻你 2021-02-04 04:31

How to upload a file on Google Cloud, in a specific bucket directory (e.g. foo)?

\"use strict\";

const gcloud = require(\"gcloud\");

const PROJECT         


        
6条回答
  •  萌比男神i
    2021-02-04 05:23

    If you want to use async-await while uploading files into storage buckets the callbacks won't do the job, Here's how I did it.

    async function uploadFile() {
        const destPath = 'PATH_TO_STORAGE/filename.extension';
    
        await storage.bucket("PATH_TO_YOUR_BUCKET").upload(newFilePath, {
            gzip: true,
            destination: destPath,  
        });
    }
    

    Hope it helps someone!

提交回复
热议问题