Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to upload file to virtual folder in blob container?

I’m currently working on a function to upload a file to a virtual folder that is in my blob container. E.g. I want to upload the file into "container1\folder" rather than "container1".

So far, I am able to upload the file directly into the container with the following code:

filename = "test.txt"
file_path = "C:\Users\____\Desktop\test.txt"

blob_client = blob_service_client.get_blob_client(container='container1', blob=filename)
with open(file_path, "rb") as data:
  blob_client.upload_blob(data)

Any tips or suggestions on how to upload the file into a virtual folder would be much appreciated.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can just prepend the path to the filename

var file_name = "file.txt";

var folder_name = "folder1";

var blobpath = f"{folder_name}/{file_name}";

file_path = "C:\Users\____\Desktop\test.txt"

blob_client = blob_service_client.get_blob_client(container='container1', blob=blob_path)
with open(file_path, "rb") as data:
  blob_client.upload_blob(data)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading