1

I have node js server service running on a Google Cloud App Engine. I have JSON file in the assets folder of the project that needs to update by the process. I was able to read the file and configs inside the file. But when adding the file getting Read-Only service error from the GAE.

Is there a way I could write the information to the file without using the cloud storage option ?

It a very small file and using the cloud storage thing would be using a very big drill machine for a Allen wrench screw

Thanks

LReddy
  • 117
  • 17

2 Answers2

3

Nope, in App Engine Standard there is no such a file system. In the docs, the following is mentioned:

The runtime includes a full filesystem. The filesystem is read-only except for the location /tmp, which is a virtual disk storing data in your App Engine instance's RAM.

So having this consideration you can write in /tmp but I suggest to Cloud Storage because if the scaling shutdowns all the instances, the data will be lost.

Also you can think of App Engine Flex which offers to have a HDD (because its backend is a VM) but the minimum size is 10GB so it will be worst than using Storage.

Puteri
  • 3,348
  • 4
  • 12
  • 27
  • Yup. Be careful when modifying files in the cloud – I'd suggest using firestore or storage to dump your json. You can load the newest / save to new version on each edit (unless the number of edits become ridiculous). – Yaakov Bressler Jun 28 '20 at 23:39
  • Thank you for the solution. I think I will using the cloud storage for this one because there aren't to going to be too much data or ridiculous edits. – LReddy Jun 30 '20 at 14:59
  • We need access to tmp for image compression libraries. – Oliver Dixon Apr 24 '22 at 11:46
0

Once thanks for steering me not to waste time finding a hack solution for the problem.

Any way there was no clear code how to use the /tmp directory and download/upload the file using the app engine hosted node.js application. Here is the code if some one needs it

const {
    Storage
} = require('@google-cloud/storage');
const path = require('path');

class gStorage {
    constructor() {
        this.storage = new Storage({
            keyFile: 'Please add path to your key file'
        });
        this.bucket = this.storage.bucket(yourbucketname);
        this.filePath = path.join('..', '/tmp/YourFileDetails');
        // I am using the same file path and same file to download and upload
    }

    async uploadFile() {
        try {
            await this.bucket.upload(this.filePath, {
                contentType: "application/json"
            });
        } catch (error) {
            throw new Error(`Error when saving the config. Message :  ${error.message}`);
        }
    }

    async downloadFile() {
        try {
            await this.bucket.file(filename).download({
                destination: this.filePath
            });
        } catch (error) {
            throw new Error(`Error when saving the config. Message :  ${error.message}`);
        }
    }
}
LReddy
  • 117
  • 17