How to upload a large file through the Azure function?

I am learning the features of Azure. The scripts I've tested so far work just fine.

I am at the point where I am trying to figure out a way to download files (20MB +) through Azure Function.

The idea is that the Azure function will first check to see if the authenticated user is allowed to download the file before it holds the request stream and stores it in the BLOB repository.

Here is the client-side code that creates StreamContentfor StreamContentbytes to the server:

using (Stream fileStream = ...)
{
    var streamContent = new StreamContent(fileStream);

    streamContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
    streamContent.Headers.ContentLength = fileStream.Length;
    streamContent.Headers.Add("FileId", fileId);

    var responseMessage = await m_httpClient.PutAsync(<validURI>, streamContent);

    responseMessage.EnsureSuccessStatusCode();

    succeeded = true;
}

Here is the server side code.

[FunctionName("upload-data")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "put")]HttpRequestMessage req, TraceWriter log)
{
    try
    {
         //  Initialize stuff.

         //  Validate authenticated user & privileges.  

         //  Get the content stream of the request and 
         //  save it in the BLOB storage.

         return req.CreateResponse(HttpStatusCode.OK);
    }
    catch (Exception exc)
    {
        return req.CreateResponse(HttpStatusCode.InternalServerError, exc);
    }
}

I put a breakpoint at the beginning of the method. I expected the breakpoint to be deleted right after the client side sends the request, no matter how big the file is. However, it is not.

, Azure Function - . , , 4 -, .

Azure Function ? ?

+8
4

-. , .

, Azure ( Identity, Framework) ( , , ).

Azure . SAS Blob " " ( Azure).

SAS Blob. , , Afzaal Ahmad Zeeshan, , Azure .

+7

, Kzrystof. Azure . , - , , Azure Function , .

, .

, , . , . , https://docs.microsoft.com/en-us/azure/azure-functions/functions-best-practices.

, App Service → Azure Storage → . .

, , App Service , , . ASP.NET Core -, , 20 .

? Blob, Blob ,

, . . , , , . , , .

, , - -, , ( ) Identity, App , , Blob & rarr, , , .

, , Azure, WebHooks, Blob Azure Function — . , Blob Storage , https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-storage-blob-triggered-function.

+4

ContentLength, . PushStreamContent .

, . , - Azure Functions , .

+1

(, ) - . .

:

  • Front End - send multiple fragments to the endpoint (multiple POST)
  • Back End - Piece Shops
  • Front End - after sending is completed, confirm with the endpoint
  • Back End - combines pieces

Dropzone JS - Chunking

0
source

Source: https://habr.com/ru/post/1685795/


All Articles