Upload a file to Google Cloud, in a specific directory

前端 未结 6 1656
借酒劲吻你
借酒劲吻你 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条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-04 05:21

    Here you go...

    const options = {
      destination: 'folder/new-image.png',
      resumable: true,
      validation: 'crc32c',
      metadata: {
        metadata: {
          event: 'Fall trip to the zoo'
        }
      }
    };
    
    bucket.upload('local-image.png', options, function(err, file) {
      // Your bucket now contains:
      // - "new-image.png" (with the contents of `local-image.png')
    
      // `file` is an instance of a File object that refers to your new file.
    });
    

提交回复
热议问题