Skip to main content
added 9 characters in body
Source Link
Joseph Xu
  • 6.1k
  • 2
  • 7
  • 17

Reference to the documentation. I've created a test to upload local file to a folder of my Azure data lake.
This is my local project file structure

enter image description here:
enter image description here

The file was uploaded to the folder of my Azure data lake. enter image description here

This is my python code

 import os, uuid from azure.storage.filedatalake import DataLakeServiceClient # Create a file in local data directory to upload and download local_path = "./data" local_file_name = "quickstart" + str(uuid.uuid4()) + ".txt" upload_file_path = os.path.join(local_path, local_file_name) # Write text to the file file = open(upload_file_path, 'w') file.write("Hello, World!") file.close() #upload the file to the folder file_system_client = service_client.get_file_system_client(file_system="test10") directory_client = file_system_client.get_directory_client("data") file_client = directory_client.create_file(local_file_name) local_file = open(upload_file_path, 'rb') file_contents = local_file.read() file_client.append_data(data=file_contents, offset=0, length=len(file_contents)) file_client.flush_data(len(file_contents)) 

Reference to the documentation. I've created a test to upload local file to a folder of my Azure data lake.
This is my local file structure

enter image description here

The file was uploaded to the folder of my Azure data lake. enter image description here

This is my python code

 import os, uuid from azure.storage.filedatalake import DataLakeServiceClient # Create a file in local data directory to upload and download local_path = "./data" local_file_name = "quickstart" + str(uuid.uuid4()) + ".txt" upload_file_path = os.path.join(local_path, local_file_name) # Write text to the file file = open(upload_file_path, 'w') file.write("Hello, World!") file.close() #upload the file to the folder file_system_client = service_client.get_file_system_client(file_system="test10") directory_client = file_system_client.get_directory_client("data") file_client = directory_client.create_file(local_file_name) local_file = open(upload_file_path, 'rb') file_contents = local_file.read() file_client.append_data(data=file_contents, offset=0, length=len(file_contents)) file_client.flush_data(len(file_contents)) 

Reference to the documentation. I've created a test to upload local file to a folder of my Azure data lake.
This is my local project file structure:
enter image description here

The file was uploaded to the folder of my Azure data lake. enter image description here

This is my python code

 import os, uuid from azure.storage.filedatalake import DataLakeServiceClient # Create a file in local data directory to upload and download local_path = "./data" local_file_name = "quickstart" + str(uuid.uuid4()) + ".txt" upload_file_path = os.path.join(local_path, local_file_name) # Write text to the file file = open(upload_file_path, 'w') file.write("Hello, World!") file.close() #upload the file to the folder file_system_client = service_client.get_file_system_client(file_system="test10") directory_client = file_system_client.get_directory_client("data") file_client = directory_client.create_file(local_file_name) local_file = open(upload_file_path, 'rb') file_contents = local_file.read() file_client.append_data(data=file_contents, offset=0, length=len(file_contents)) file_client.flush_data(len(file_contents)) 
added 1 character in body
Source Link
Joseph Xu
  • 6.1k
  • 2
  • 7
  • 17

RefrenceReference to the documentation. I've created a test to upload local file to a folder of my Azure data lake.
This is my local file structure

enter image description here

The file was uploaded to the folder of my Azure data lake. enter image description here

This is my python code

 import os, uuid from azure.storage.filedatalake import DataLakeServiceClient # Create a file in local data directory to upload and download local_path = "./data" local_file_name = "quickstart" + str(uuid.uuid4()) + ".txt" upload_file_path = os.path.join(local_path, local_file_name) # Write text to the file file = open(upload_file_path, 'w') file.write("Hello, World!") file.close() #upload the file to the folder file_system_client = service_client.get_file_system_client(file_system="test10") directory_client = file_system_client.get_directory_client("data") file_client = directory_client.create_file(local_file_name) local_file = open(upload_file_path, 'rb') file_contents = local_file.read() file_client.append_data(data=file_contents, offset=0, length=len(file_contents)) file_client.flush_data(len(file_contents)) 

Refrence to the documentation. I've created a test to upload local file to a folder of my Azure data lake.
This is my local file structure

enter image description here

The file was uploaded to the folder of my Azure data lake. enter image description here

This is my python code

 import os, uuid from azure.storage.filedatalake import DataLakeServiceClient # Create a file in local data directory to upload and download local_path = "./data" local_file_name = "quickstart" + str(uuid.uuid4()) + ".txt" upload_file_path = os.path.join(local_path, local_file_name) # Write text to the file file = open(upload_file_path, 'w') file.write("Hello, World!") file.close() #upload the file to the folder file_system_client = service_client.get_file_system_client(file_system="test10") directory_client = file_system_client.get_directory_client("data") file_client = directory_client.create_file(local_file_name) local_file = open(upload_file_path, 'rb') file_contents = local_file.read() file_client.append_data(data=file_contents, offset=0, length=len(file_contents)) file_client.flush_data(len(file_contents)) 

Reference to the documentation. I've created a test to upload local file to a folder of my Azure data lake.
This is my local file structure

enter image description here

The file was uploaded to the folder of my Azure data lake. enter image description here

This is my python code

 import os, uuid from azure.storage.filedatalake import DataLakeServiceClient # Create a file in local data directory to upload and download local_path = "./data" local_file_name = "quickstart" + str(uuid.uuid4()) + ".txt" upload_file_path = os.path.join(local_path, local_file_name) # Write text to the file file = open(upload_file_path, 'w') file.write("Hello, World!") file.close() #upload the file to the folder file_system_client = service_client.get_file_system_client(file_system="test10") directory_client = file_system_client.get_directory_client("data") file_client = directory_client.create_file(local_file_name) local_file = open(upload_file_path, 'rb') file_contents = local_file.read() file_client.append_data(data=file_contents, offset=0, length=len(file_contents)) file_client.flush_data(len(file_contents)) 
Source Link
Joseph Xu
  • 6.1k
  • 2
  • 7
  • 17

Refrence to the documentation. I've created a test to upload local file to a folder of my Azure data lake.
This is my local file structure

enter image description here

The file was uploaded to the folder of my Azure data lake. enter image description here

This is my python code

 import os, uuid from azure.storage.filedatalake import DataLakeServiceClient # Create a file in local data directory to upload and download local_path = "./data" local_file_name = "quickstart" + str(uuid.uuid4()) + ".txt" upload_file_path = os.path.join(local_path, local_file_name) # Write text to the file file = open(upload_file_path, 'w') file.write("Hello, World!") file.close() #upload the file to the folder file_system_client = service_client.get_file_system_client(file_system="test10") directory_client = file_system_client.get_directory_client("data") file_client = directory_client.create_file(local_file_name) local_file = open(upload_file_path, 'rb') file_contents = local_file.read() file_client.append_data(data=file_contents, offset=0, length=len(file_contents)) file_client.flush_data(len(file_contents))