skip to Main Content

I have an API that allows users to upload and download files to my Azure Storage containers. With downloading files I have a simple function in my HTML script that uses user input information (SAS tokens, etc.) to create a URL where the user can download their file.

With file uploads, however, I have a whole separate Azure Function creating Blob Clients and Container Clients to upload data to Azure Storage containers. I was wondering if there was a simpler way to upload files to Azure Storage containers using a URL, with minimal code similar to how Azure Storage container file downloads work.

2

Answers


  1. I was wondering if there was a simpler way to upload files to Azure Storage containers using a URL

    AFAIK, you need the container and blob clients to upload a file. Alternatively, you can use below commands in azure PowerShell Function with which you do not need clients.

    You can integrate below commands into Azure PowerShell Function which do not uses clients:

    $SASURL="https://rithwik.blob.core.windows.net/rithwik?sp==https&svV6V3dI0KJRxDY%2FtXh5jj8m%2BL8YpYU%3D"
    $u = [System.Uri] $SASURL
    
    $s = "rithwik"
    $con = "rithwik"
    $sas = $u.Query
    $Context = New-AzStorageContext -StorageAccountName $s -SasToken $sas
    Set-AzStorageBlobContent -File "C:UsersDownloads76210027.html" -Container $con -Context $Context
    

    enter image description here

    File Uploaded as below:

    enter image description here

    And if you want to use . Net, Python SDKs or java you need to have the clients of block service or some azure storage packages.

    Login or Signup to reply.
  2. If I understand correctly, you are asking whether it is possible to create a container and / or upload a blob using http calls instead of the SDK. If that is the case you can leverage the REST Api.

    For the examples below, I used a SAS token to authenticate,

    To create a container you can use a PUT like this:

    PUT https://myaccount.blob.core.windows.net/mycontainer?restype=container&sv=2021-10-04&ss=btqf&srt=sco&st=2023-05-12T06%3A48%3A03Z&se=2023-05-13T06%3A48%3A03Z&sp=rwl&sig=I8EPwY4xhBWSbQKbPbasyXWnjwD%2BJTg8jHExZi9%2BU0w%3D
    

    To upload a blob to the container you can use a PUT as well

    PUT https://myaccount.blob.core.windows.net/mycontainer/myblob.txt?sv=2021-10-04&ss=btqf&srt=sco&st=2023-05-12T06%3A48%3A03Z&se=2023-05-13T06%3A48%3A03Z&sp=rwl&sig=I8EPwY4xhBWSbQKbPbasyXWnjwD%2BJTg8jHExZi9%2BU0w%3D
    x-ms-blob-type: BlockBlob  
    
    HELLO WORLD
    

    (Note: I used an .http file in visual studio to create the examples, see this blog post. So the code above can be put in a file with .http extension to test it)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search