Home > OS >  Is it possible to upload files to Azure Storage Account using the REST API without passing headers?
Is it possible to upload files to Azure Storage Account using the REST API without passing headers?

Time:03-04

Background of my question is that I want to write a custom API that receives file upload requests, validates them, generates a SAS token with the required permissions and returns an HTTP 301 to the calling client containing the URI of an Azure Storage Account with all the required query parameters, for example https://mystorage.file.core.windows.net/share/movie.avi?srt=sco&sv=2020-02-10&ss=f&sp=rwdlacup&st=2022-03-02T14:10:19Z&se=2022-03-02T15:10:19Z&sig=ABC=.

The problem is that both, the Blob Storage REST API and the File Storage REST API need required HTTP headers. This in turn would require the client to set those which I want to avoid, in the best case the client only sends a PUT https://myapi.com/upload with some authentication information and gets back an URI which contains all the necessary parameters to upload files.

The alternative is that the client sends his files to https://myapi.com/upload and the API then takes care of uploading the file to the storage account. Given that the files can get large, I want to avoid this additional overhead, upload the files directly to the destination and use the API just as a validator and SAS provider (as in the second part of this graphics).

CodePudding user response:

Is it possible to upload files to Azure Storage Account using the REST API without passing headers?

It is not possible to do so. With Shared Access Signature (SAS), you can omit some of the required headers but not all.

For example, when uploading blobs you must include x-ms-blob-type header.

When uploading a file in file storage, things become a bit complicated as uploading a file is a two step process: 1) You create an empty file using Create File request and here you have to specify x-ms-content-length request header and 2) You push the data into this file using Put Range request and here you have to specify range (or x-ms-range) and x-ms-write headers.

  • Related