I want to create folders using flask to store in azure blob . I need help to write the code in flask to store all the files of a registration page to a folder and that folder to be uploaded in azure blob storage.
I want to create folders for every user at register time. So how can I create a simple empty folder at particular path in flask.
i tried uploading the files from the web page to the azure blob storage and all files are getting uploaded. but i want a separate folder to every single user who registers and this folders to be uploaded in the blob storage
This is the code of app.py to upload the files to blob storage:
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in allowed_ext
@app.route('/upload',methods=['POST'])
def upload():
if request.method == 'POST':
files = request.files.getlist('file')
for file in files:
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(filename)
blob_client = blob_service_client.get_blob_client(container = container, blob = filename)
with open(filename, "rb") as data:
try:
blob_client.upload_blob(data, overwrite=True)
msg = "Upload Done ! "
except:
pass
os.remove(filename)
return render_template("dashboard.html", msg=msg)
This is the html code of the files to be uploaded:
<form action="/upload" method="POST" enctype="multipart/form-data">
<div><label>Bank Statement*</label><input type="file" name="file" ></div>
<div><label>Affidant of support in case of someone sponsoring the education*</label><input type="file" name="file" ></div>
<div><label>Test of English Fulency- Duolingo/GRE/IELTS/TOEFL/OTHERS*</label><input type="file" name="file"></div>
<div><label>2022-23 River Certificate of finances for international students*</label><input type="file" name="file" ></div>
<hr>
<div class="button">
<input type="submit" name="upload" value="Upload" class="btn btn-success">
</div>
{{msg}}
</form>