Uploading a buffer to google cloud storage

后端 未结 4 607
无人及你
无人及你 2021-02-07 06:27

I\'m trying to save a Buffer (of a file uploaded from a form) to Google Cloud storage, but it seems like the Google Node SDK only allows files with a given path to be uploaded (

4条回答
  •  误落风尘
    2021-02-07 06:44

    .save to save the day! Some code below where I save my "pdf" that I created.

    https://googleapis.dev/nodejs/storage/latest/File.html#save

    const { Storage } = require("@google-cloud/storage");
    
    const gc = new Storage({
      keyFilename: path.join(__dirname, "./path to your service account .json"),
      projectId: "your project id",
    });
    
          const file = gc.bucket(bucketName).file("tester.pdf");
          file.save(pdf, (err) => {
            if (!err) {
              console.log("cool");
            } else {
              console.log("error " + err);
            }
          });
    

提交回复
热议问题