Upload file to google cloud storage with NodeJS

前端 未结 2 2001
盖世英雄少女心
盖世英雄少女心 2021-01-02 18:53

My upload.js file contains the following code:

module.exports = {

    up: function () {
        const storage = require(\'@google-cloud/storage\');         


        
2条回答
  •  抹茶落季
    2021-01-02 19:11

    const { Storage } = require('@google-cloud/storage');
    
    const up = () => {
        const gcs = new Storage({
            projectId: 'xxxxxxxxx',
            keyFilename: './service-account.json'
        });
        const bucket = gcs.bucket('xxxxxxxxxx');
        bucket.upload('./test-rev.mkv', function (err, file) {
            if (err) throw new Error(err);
        });
    }
    

提交回复
热议问题