How do I upload a base64 encoded image (string) directly to a Google Cloud Storage bucket using Node.js?

前端 未结 6 1749
野性不改
野性不改 2020-11-30 04:51

Currently, I am using the @google-cloud/storage NPM package to upload a file directly to a Google Cloud Storage bucket. This requires some trickery as I only have the image\

6条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 05:26

    If you want to save a string as a file in Google Cloud Storage, you can do it easily using the file.save method:

    const {Storage} = require('@google-cloud/storage');
    const storage = new Storage();
    const myBucket = storage.bucket('my-bucket');
    
    const file = myBucket.file('my-file.txt');
    const contents = 'This is the contents of the file.';
    
    file.save(contents).then(() => console.log('done'));
    

提交回复
热议问题