question

AndyQuangAnhPham-1264 avatar image
0 Votes"
AndyQuangAnhPham-1264 asked AndyQuangAnhPham-1264 commented

Upload file directly to Azure Blob Storage from URL with python

I'm trying to upload file to Blob storage from the URL: https://datasets.imdbws.com/title.akas.tsv.gz without having to download to an intermediary storage location.
Can I accomplish that with Databricks notebook in Python?

I looked into the link: https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python?tabs=environment-variable-linux#upload-blobs-to-a-container
but it's not clear of dealing with URL.

There was an older version of BlobServiceClient which is BlockBlobService has the solution as below example but I couldn't find the similar one for BlobServiceClient

from azure.storage.blob import BlockBlobService, PublicAccess
from azure.storage.blob.models import Blob

def run_sample():

 block_blob_service = BlockBlobService(account_name='your_name', account_key='your_key')  
 container_name ='t1s'  
 block_blob_service.copy_blob(container_name,'remoteURL.pdf','https://media.readthedocs.org/pdf/azure-storage/v0.20.3/azure-storage.pdf')  

if name == 'main':
run_sample()



azure-blob-storageazure-databricks
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SumanthMarigowda-MSFT avatar image
0 Votes"
SumanthMarigowda-MSFT answered AndyQuangAnhPham-1264 commented

@AndyQuangAnhPham-1264 Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

You can perform this scenario by using CopyBlobFromUrl (service doc) as you did in previous versions. In Python Track2 that is done with the BlobClient.start_copy_from_url() method.

See our sample for this here. This sample even uses an external URL as the customer is looking to do.
azure-sdk-for-python/blob_samples_copy_blob.py at main · Azure/azure-sdk-for-python (github.com)


Please let us know if you have any further queries. I’m happy to assist you further.


Please do not forget to194017-screenshot-2021-12-10-121802.png and “up-vote!” wherever the information provided helps you, this can be beneficial to other community members.




· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks Sumarigo for the response! I really appreciate your help! :D

0 Votes 0 ·