Skip to content
Advertisement

Upload JSON string to Google Cloud Storage without a file

My case is when I receive data from some other source as a JSON string, then I want to upload this string to Google Cloud Storage without writing this string to a local file and upload this file. Is there any way to do this. Thank you. Look like this code below

storage
  .bucket(bucketName)
  .upload(jsonString, { destination: 'folder/test.json' })
  .then(() => {
    console.log('success');
  })
  .catch((err) => {
    console.error('ERROR:', err);
  });

so I expected the Google Cloud Storage will have a file test.json with content from the jsonString

Advertisement

Answer

It looks like this scenario has already been addressed in this other question.

Both answers look good, but it will probably be easier to use the file.save() method (second answer).You can find the description of this method and yet another example here.

Hope this helps.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement