Dec-21-2023, 03:53 PM
Hello,
I found the script online that uploads multiple JPG files. I changed it so I can upload multiple BLOB files, i.e.) csv, xls, etc. However, I am receiving the following error message when I run the script:
Here is the script:
I found the script online that uploads multiple JPG files. I changed it so I can upload multiple BLOB files, i.e.) csv, xls, etc. However, I am receiving the following error message when I run the script:
Error:azure.core.exceptions.HttpResponseError: The specifed resource name contains invalid characters.
RequestId:62
Time:2023-12-21T15:42:33.3507947Z
ErrorCode:InvalidResourceName
Content: <?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidResourceName</Code><Message>The specifed resource name contains invalid characters.
RequestId:62
Time:2023-12-21T15:42:33.3507947Z</Message></Error>
The file names are lowercase and alphanumeric: bcp-notes-batch-0.csvHere is the script:
# Replace with blob container MY_IMAGE_CONTAINER = "source_system" # Replace with the local folder which contains the files for upload LOCAL_FILE_PATH = 'I:/bcp' class AzureBlobFileUploader: def __init__(self): print("Initializing AzureBlobFileUploader") # Initialize the connection to Azure storage account 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): 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) content_settings = ContentSettings(content_type='application/octet-stream') print(f"Uploading file - {file_name}") with open(upload_file_path, "rb") as data: blob_client.upload_blob(data, overwrite=True, content_settings=content_settings) return file_name # Initialize class and upload files azure_blob_file_uploader = AzureBlobFileUploader() azure_blob_file_uploader.upload_all_files_in_folder()