padmaja cherukuri
padmaja cherukuri

Reputation: 413

How to get the filepath while uploading a file to azure-storage in django

I have a form in which files can be uploaded. the uploaded file has to be stored in azure-storage. I am using create_blob_from_path to upload a file to azure-storage.create_blob_from_path expects file path as one of the parameters. but how can I get file path in this case as the operation has to be in on the fly mode(The uploaded file cannot be stored in any local storage).it should get stored directly in Azure.

if request.method=="POST":
    pic=request.FILES['pic']
    block_blob_service = BlockBlobService(account_name='samplestorage', account_key='5G+riEzTzLmm3MR832NEVjgYxaBKA4yur6Ob+A6s5Qrw==')
    container_name ='quickstart'
    block_blob_service.create_container(container_name)        
    block_blob_service.set_container_acl(container_name, public_access=PublicAccess.Container)
    block_blob_service.create_blob_from_path(container_name, pic, full_path_to_file)//full_path_to_file=?

the file uploaded dynamically has to be stored in Azure

Upvotes: 0

Views: 447

Answers (1)

Ivan Glasenberg
Ivan Glasenberg

Reputation: 29950

If the uploaded file cannot be stored in any local storage, you can read the file content as stream or text(string), then use the create_blob_from_stream or create_blob_from_text method respectively.

Upvotes: 1

Related Questions