1

I have created an App in Nodejs, this App involves users to upload some files such as profile pictures and some other media file, so these files are stored in certain folders here in my Web Application folder.

This works well locally now after deploying my App when the user do an upload these picture and other files it return an error, I suppose I should be maybe doing some configuration on Cloud Storage and let my App Engine Application be able to read and write to such folder using NodeJs. Please help me with how I can achieve this.

I use this following Code to create these files from Base64 data which is Uploaded using Rest API

var data = req.body.image;    //base64 image data
const bucket = storage.bucket(process.env.GCLOUD_STORAGE_BUCKET);   //decalre bucket
var blob = bucket.file('new_image.png');
writeScreenShot(blob, data);

blobStream.on('finish', () => {
    res.send("Success");
});


blobStream.end(req.file.buffer);

function writeScreenShot(blob, data) 
{
    var strm = blob.createWriteStream();
    strm.write(new Buffer(data, 'base64'));
    strm.end();
}

This is how I implemented it so far, but it returns image that says it looks like we don't support this image type while file extension of this image is png, it seems like I have created this image wrongly now got affected the metadata of it. Thanks in advance

  • Hi, Welcome to stack overflow. Please share with us more information. How are you uploading the files to Cloud Storage? Which errors are you encountering, can you please add it to the question? Also I would recommend you to see the [best practices to upload files to Cloud Storage from App Engine](https://cloud.google.com/appengine/docs/flexible/nodejs/using-cloud-storage) – Chris32 Oct 07 '19 at 08:01
  • Indeed, need a stacktrace and maybe more code. Here I don't see how you write on Storage. – guillaume blaquiere Oct 07 '19 at 14:54
  • Than you guys for responses, I followed the tutorial with link on ***@Christian Gonzalez*** [link](https://cloud.google.com/appengine/docs/flexible/nodejs/using-cloud-storage). Can I update my code with now the updated version after I have followed such documentation and also some posts here on StackOverflow. From front end I receive base64 data of png image, now it is the one I want to store in my bucket, inside a folder called ***images*** – nasiphi vinqishe Oct 08 '19 at 16:08
  • Sorry for the late reply, I was busy trying to search for solution – nasiphi vinqishe Oct 08 '19 at 16:42
  • Thank you guys, this helped me to add from the link you provided me to get solution: [link](https://stackoverflow.com/questions/42879012/how-do-i-upload-a-base64-encoded-image-string-directly-to-a-google-cloud-stora?rq=1) – nasiphi vinqishe Oct 08 '19 at 18:26

0 Answers0