How to upload a file in a nested directory to Storage accounts File Share service using Python SDK ?

Vaibhav Jain 40 Reputation points
2023-07-24T05:30:39.9633333+00:00

I am trying to upload a file to the path, using ShareDirectoryClient Class of Azure Python SDK.
I have attached below the code and errors that I am getting.

path = "users/vaibhav11/projects/assets/fbx"
directories = path.lower().strip("/").split("/")
for directory in directories:
	try:    
		directory_client = directory_client.get_subdirectory_client(directory)
		if not directory_client.exists():
			directory_client.create_directory()
	except Exception as e:
		print(e.args)

with directory_client.get_file_client(file_name=upload_file.name) as file_client:
	file_client.upload_file(data = file_content, length=len(file_content))
	print("Uploaded")

The "directory_client" is an object of ShareDirectoryClient, which is used in the above code snippet to create directories. The problem faced is, with every directory that is being created I get the below Exception.

('The specifed resource name contains invalid characters.\nRequestId:fc43b173-e01a-000c-1ae8-bd388a000000\nTime:2023-07-24T04:37:52.5072468Z\nErrorCode:InvalidResourceName',)

ClientAuthenticationError

Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. 
ErrorCode:AuthenticationFailed authenticationerrordetail:The MAC signature found in the HTTP request 'E0eObuCq+OdHAtf4qG80kb3wprxR4vwIsDpjinnVvUM=' is not the same as any computed signature. Server used following string to sign: 'PUT.......'

And sometimes I even get ClientAuthenticationError. I'm not really sure, what is creating the problem in both the cases.

Any solutions and suggestions are open.

Thanks!

Azure Files
Azure Files

An Azure service that offers file shares in the cloud.

Azure Storage
Azure Storage

Globally unique resources that provide access to data management services and serve as the parent namespace for the services.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    1 deleted comment

    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.