It is not a problem to upload file from local path (from my computer). However, I didn't find how to upload from specific URL.
If it possible - solution in Python is needed. There is documentation only for local files https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python
How to do this for remote URL?
By default, the URL for accessing the Blob service in a storage account is https://<your account name>. blob.core.windows.net. You can map your own domain or subdomain to the Blob service for your storage account so that users can reach it using the custom domain or subdomain.
Run project locally to verify connection to Storage account. Your SAS token and storage account name are set in the src/azure-storage-blob. ts file, so you are ready to run the application. Select an image from the images folder to upload then select the Upload!
Create an access policy with write permission. Create an asset. Create a SAS locator and create the upload URL. Upload a file to blob storage using the upload URL.
You can make use of async copy blob
functionality to create a blob from a publicly accessible URL. Please see sample code below:
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')
# Main method.
if __name__ == '__main__':
run_sample()
You can first download the file as stream
, then call the method create_blob_from_stream
.
The following is a demo code:
from azure.storage.blob import BlockBlobService, PublicAccess
from azure.storage.blob.models import Blob
import requests
def run_sample():
block_blob_service = BlockBlobService(account_name='your_name', account_key='your_key')
container_name ='t1s'
response = requests.get('https://media.readthedocs.org/pdf/azure-storage/v0.20.3/azure-storage.pdf',stream=True)
block_blob_service.create_blob_from_stream(container_name,'remoteURL.pdf',response.raw)
# Main method.
if __name__ == '__main__':
run_sample()
Test result as below:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With