Dec-21-2023, 07:24 PM
(Dec-21-2023, 06:50 PM)deanhystad Wrote: According to azure documentation:
Quote:A path name is composed of one or more path name components (directory or file name) separated by the forward-slash (/) character. All path name components other than the last path name component denote directories. The last path name component denotes a directory or a file.Is the problem that os.path.join(LOCAL_FILE_PATH, file_name) uses '\'?
Still no luck:
class AzureBlobFileUploader: def __init__(self): print("Initializing AzureBlobFileUploader") self.blob_service_client = BlobServiceClient.from_connection_string(MY_CONNECTION_STRING) def upload_all_files_in_folder(self): all_file_names = [f for f in os.listdir(LOCAL_FILE_PATH) if os.path.isfile(os.path.join(LOCAL_FILE_PATH, f))] result = self.run(all_file_names) print(result) def run(self, all_file_names): with ThreadPool(processes=int(10)) as pool: return pool.map(self.upload_file, all_file_names) def upload_file(self, file_name): try: print(repr(file_name)) # Print the repr() of the file name blob_client = self.blob_service_client.get_blob_client(container=MY_IMAGE_CONTAINER, blob=file_name) upload_file_path = os.path.join(LOCAL_FILE_PATH, file_name).replace('\\', '/') # Replace backslashes print(f"Uploading file - {file_name}") with open(upload_file_path, "rb") as data: blob_client.upload_blob(data, overwrite=True) return file_name except Exception as e: print(f"Exception uploading file - {repr(file_name)}: {e}") def get_containers(self): try: containers = self.blob_service_client.list_containers() print([container.name for container in containers]) except Exception as e: print(e.message) # Initialize class and upload files azure_blob_file_uploader = AzureBlobFileUploader() azure_blob_file_uploader.get_containers() azure_blob_file_uploader.upload_all_files_in_folder()
Error:Initializing AzureBlobFileUploader
'ibrtfnotesbatch00.csv'
'ibrthnotesbatch01.csv'
Uploading file - ibrtfnotesbatch00.csv
Uploading file - ibrthnotesbatch01.csv
Exception uploading file - 'ibrtfnotesbatch00.csv': The specifed resource name contains invalid characters.
RequestId:1b87ffae-901e-0077-4242-34969d000000
Time:2023-12-21T19:17:32.3704303Z
ErrorCode:InvalidResourceName
Content: <?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidResourceName</Code><Message>The specifed resource name contains invalid characters.
RequestId:1b87ffae-901e-0077-4242-34969d000000
Time:2023-12-21T19:17:32.3704303Z</Message></Error>
Exception uploading file - 'ibrthnotesbatch01.csv': The specifed resource name contains invalid characters.
RequestId:74f78216-701e-0040-3a42-344431000000
Time:2023-12-21T19:17:41.6794092Z
ErrorCode:InvalidResourceName
Content: <?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidResourceName</Code><Message>The specifed resource name contains invalid characters.
RequestId:74f78216-701e-0040-3a42-344431000000
Time:2023-12-21T19:17:41.6794092Z</Message></Error>
[None, None]