简体   繁体   中英

Where are files saved in gloud python app deployment.?

I have deployed a python flask app in google cloud which generates a json file. Here is a code snippet:

@app.route('/save_data', methods=['POST'])
def index():

    try:
        raw_data = request.get_json()
        print(raw_data)
        with open("data.json", 'w') as fp:
            json.dump(raw_data, fp, indent=4, ensure_ascii=False)
        return jsonify({'Status': 'OK'}), 200
    except Exception as e:
        print(e)

When a user calls this api, data.json file is created. I can see logs using gcloud app logs tail -s default and the file being created but I am not sure where it is saved. I have checked the project directory but the file is not there. Can anyone please guide me where this file is saved. Thanks

I would suggest to use Cloud Storage for saving files.

Reading and Writing Temporary Files

According to official documentation:

While Cloud Storage is the recommended solution for reading and writing files in App Engine, if your app only needs to write temporary files, you can use standard Python 3.7 methods to write files to a directory named /tmp.

All files in this directory are stored in the instance's RAM, therefore writing to /tmp takes up system memory. In addition, files in the /tmp directory are only available to the app instance that created the files. When the instance is deleted, the temporary files are deleted.

Therefore your files are stored on /tmp folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM