I have a web application on GAE node.js standard environment. The server receives a POST request containing json in its body (not ready json file). I want to write this json file to Cloud Storage. How to do this?
Asked
Active
Viewed 114 times
0
-
1Please share what you have tried so far. – google cloud sucks Jan 23 '22 at 19:52
3 Answers
1
You have to get the body (the JSON) and save it in a cloud storage file. That should be enough
guillaume blaquiere
- 52,509
- 2
- 22
- 50
0
To consume the body of your post request, you can check a previous discussion here. On the other hand, if you specifically want to convert it to a JSON file, check this other post. Continuing with the upload, you can consult the documentation example where this is the suggested procedure (please visit the page for the full script for the recommended variable paths and the links to the Cloud Storage Node.js API reference):
// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');
// Creates a client
const storage = new Storage();
async function uploadFile() {
await storage.bucket(bucketName).upload(filePath, {
destination: destFileName,
});
console.log(`${filePath} uploaded to ${bucketName}`);
}
uploadFile().catch(console.error);
Alex
- 678
- 13
0
You need to write JSON file to /tmp directory using fs.createWriteStream and then write it to Storage using Storage API
Vladyslav Yukhanov
- 377
- 2
- 7