Home > Net >  Azure blob storage trying to upload the same file to different folders
Azure blob storage trying to upload the same file to different folders

Time:12-09

I am trying to upload multiple files with the name 'data' to the Azure blob, I am uploading them in different folders in my function, I create a new one for each new 'data' file, but still I get the error BlobAlreadyExistsThe specified blob already exists.Any ideas ?

`

 blob_service_client = BlobServiceClient.from_connection_string(connection_string)
 blob_client = blob_service_client.get_blob_client(container=container_name '\\' id '\\' uploadnr, blob=filename)
 with open(pathF filename,"rb") as data:
      blob_client.upload_blob(data)
      print(f"Uploaded {filename}.")

`

CodePudding user response:

I tried in my environment and got below results:

BlobAlreadyExistsThe specified blob already exists.

Initially I tried in my environment and got same results:

Code:

from  azure.storage.blob  import  BlobServiceClient

connection_string="<Connect_string>"
container="test\data"
filename="sample1.pdf"
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
blob_client = blob_service_client.get_blob_client(container,filename)
with  open("path filename","rb") as  data:
blob_client.upload_blob(data)
print(f"Uploaded {filename}.")

Console:

enter image description here

After I made changes in code it executed successfully.

enter image description here

  • Related