I developed a flask application for a demo. Since it was a demo, I didn't want to complicate it by adding SQL and blob storage from azure. There are 2 portals in this application user and admin. The user comes in and uploads the documents and the application creates a summary file and stores it in a folder called summary. In the admin side, when he logs in he can see the extracted information from the summary folder in the form of table. This is working prefect in the local but after deployment, in the admin side, I am not able to see the extracted info. So I think the summary file is not generated and stored.
I tried changing the relative path to absolute path. But it didn't work.
I developed a flask application for a demo. Since it was a demo, I didn't want to complicate it by adding SQL and blob storage from azure. There are 2 portals in this application user and admin. The user comes in and uploads the documents and the application creates a summary file and stores it in a folder called summary. In the admin side, when he logs in he can see the extracted information from the summary folder in the form of table. This is working prefect in the local but after deployment, in the admin side, I am not able to see the extracted info. So I think the summary file is not generated and stored.
I tried changing the relative path to absolute path. But it didn't work.
Share Improve this question edited Mar 19 at 17:32 James Z 12.3k10 gold badges27 silver badges47 bronze badges asked Mar 19 at 10:06 Fredrick SebastianFredrick Sebastian 11 bronze badge 1 |1 Answer
Reset to default 0I've created a sample Flask application and successfully uploaded files to Azure App Service.
- The issue you're facing might be due to storing files in
wwwroot
, which does not persist files in Azure App Service. Any files saved there will be deleted when the app restarts or is redeployed. - Any file stored outside persistent directories is lost when the app restarts.
- For long-term file storage, it's recommended to use
Azure Blob Storage
instead of local storage.
Instead of wwwroot
, I stored files in /home/summary
, which is retained across deployments.
My main .py:
from flask import Flask, request, jsonify, send_from_directory
import os
app = Flask(__name__)
UPLOAD_FOLDER = "/home/summary"
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
@app.route("/upload", methods=["POST"])
def upload_file():
if "file" not in request.files:
return jsonify({"error": "No file part"}), 400
file = request.files["file"]
if file.filename == "":
return jsonify({"error": "No selected file"}), 400
file_path = os.path.join(UPLOAD_FOLDER, file.filename)
file.save(file_path)
return jsonify({"message": f"File saved at {file_path}"}), 200
@app.route("/files", methods=["GET"])
def list_files():
try:
files = os.listdir(UPLOAD_FOLDER)
return jsonify({"files": files})
except Exception as e:
return jsonify({"error": str(e)}), 500
@app.route("/files/<filename>", methods=["GET"])
def get_file(filename):
try:
return send_from_directory(UPLOAD_FOLDER, filename, as_attachment=True)
except Exception as e:
return jsonify({"error": str(e)}), 404
if __name__ == "__main__":
app.run(debug=True)
I've successfully uploaded the files to Azure.
Uploaded files correctly stored in /home/summary
.
Files are listed successfully.
/home/site/wwwroot/summary
directory and check if files are created. – Sirra Sneha Commented Mar 19 at 10:27