简体   繁体   English

我知道要分块上传,我们是否必须在接收端做些事情?

[英]I know about uploading in chunks, do we have to do something on receiving end?

my azure function receives large video files and images and stores it in Azure blob. 我的azure函数接收大型视频文件和图像,并将其存储在Azure blob中。 Client API is sending data in chunks to my Azure htttp trigger function. 客户端API将数据块发送到我的Azure htttp触发函数。 Do I have to do something at receiving-end to improve performance like receiving data in chunks? 我是否需要在接收端做一些事情来提高性能,例如分块接收数据?

Bruce, actually Client code is being developed by some other team. 布鲁斯,实际上客户代码是由其他团队开发的。 right now i am testing it by postman and getting files from multipart http request. 现在,我正在通过邮递员进行测试,并从多部分HTTP请求中获取文件。

foreach (HttpContent ctnt in provider.Contents)  {

                var dataStream = await ctnt.ReadAsStreamAsync();
 if (ctnt.Headers.ContentDisposition.Name.Trim().Replace("\"", "") == "file")
               {                
                        byte[] ImageBytes = ReadFully(dataStream);
                        var fileName = WebUtility.UrlDecode(ctnt.Headers.ContentDisposition.FileName);                         

              } }

ReadFully Function ReadFully功能

 public static byte[] ReadFully(Stream input){
using (MemoryStream ms = new MemoryStream())
{
    input.CopyTo(ms);
    return ms.ToArray();
}}

As BlobRequestOptions.ParallelOperationThread states as follows: 由于BlobRequestOptions.ParallelOperationThread的状态如下:

Gets or sets the number of blocks that may be simultaneously uploaded. 获取或设置可以同时上传的块数。

Remarks: 备注:

When using the UploadFrom* methods on a blob, the blob will be broken up into blocks. 在Blob上使用UploadFrom *方法时,该Blob将被分解为多个块。 Setting this value limits the number of outstanding I/O "put block" requests that the library will have in-flight at a given time. 设置此值将限制库在给定时间进行中的未完成I / O“放置块”请求的数量。 Default is 1 (no parallelism). 默认值为1(无并行性)。 Setting this value higher may result in faster blob uploads, depending on the network between the client and the Azure Storage service. 将此值设置得更高可能会导致更快的Blob上传,具体取决于客户端与Azure存储服务之间的网络。 If blobs are small (less than 256 MB), keeping this value equal to 1 is advised. 如果blob小(小于256 MB),则建议将该值保持等于1。

I assumed that you could explicitly set the ParallelOperationThreadCount for faster blob uploading. 我假设您可以显式设置ParallelOperationThreadCount以便更快地上传Blob。

var requestOption = new BlobRequestOptions()
{
    ParallelOperationThreadCount = 5 //Gets or sets the number of blocks that may be simultaneously uploaded.
};

//upload a blob from the local file system
await blockBlob.UploadFromFileAsync("{your-file-path}",null,requestOption,null);

//upload a blob from the stream
await blockBlob.UploadFromStreamAsync({stream-for-upload},null,requestOption,null);

foreach (HttpContent ctnt in provider.Contents) foreach(provider.Contents中的HttpContent ctnt)

Based on your code, I assumed that you retrieve the provider instance as follows: 根据您的代码,我假设您按以下方式检索provider实例:

MultipartMemoryStreamProvider provider = await request.Content.ReadAsMultipartAsync();

At this time, you could use the following code for uploading your new blob: 目前,您可以使用以下代码上传新的Blob:

var blobname = ctnt.Headers.ContentDisposition.FileName.Trim('"');
CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobname);
//set the content-type for the current blob
blockBlob.Properties.ContentType = ctnt.Headers.ContentType.MediaType;
await blockBlob.UploadFromStreamAsync(await ctnt.Content.ReadAsStreamAsync(), null,requestOption,null);

I would prefer use MultipartFormDataStreamProvider which would store the uploaded files from the client to the file system instead of MultipartMemoryStreamProvider which would use the server memory for temporarily storing the data sent from the client. 我更喜欢使用MultipartFormDataStreamProvider来将从客户端上传的文件存储到文件系统,而不是使用MultipartMemoryStreamProvider来使用服务器内存临时存储从客户端发送的数据。 For the MultipartFormDataStreamProvider approach, you could follow this similar issue . 对于MultipartFormDataStreamStreamProvider方法,您可以遵循类似的问题 Moreover, I would prefer use the Azure Storage Client Library with my Azure function, you could follow Get started with Azure Blob storage using .NET . 此外,我更喜欢将Azure存储客户端库与我的Azure函数一起使用,可以按照.NET入门Azure Blob存储

UPDATE: 更新:

Moreover, you could follow this tutorial about breaking a large file into small chunks, upload them in the client side, then merge them back in your server side. 此外,您可以按照本教程的有关将大文件分成小块的操作,在客户端上载它们,然后在服务器端将它们合并回去。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过流Vimeo上传。 如何以较小的部分(块)上传视频以节省存储空间? - Vimeo uploading via streaming. How do i upload the video in smaller parts(chunks) to save memory? 我怎么知道我是否要获得OutOfMemoryException? - How do I know if I'm about to get an OutOfMemoryException? 请求结束后,我该如何在控制器中执行某些操作? - How can I do something within the controller at the end of the request? 我需要做些特别的事情来覆盖jQuery的WebViewClient.ShouldInterceptRequest吗? - Is there something special I have to do to override WebViewClient.ShouldInterceptRequest for jQuery? 控制台应用程序服务-我需要注意些什么吗? - Console Application to Service - do I have to note something? 如何知道何时更改字符串并执行某些操作? - How to know when a string changed and do something? Windows Mobile:我怎么知道我是否安装了GPS? - Windows Mobile: how do I know if I have a GPS installed? 我如何知道您已登录Sharepoint网页? - How do I know you have logged in a Sharepoint WebPage? 如何知道所有控件何时加载并显示? - How do I know when all controls have loaded and displayed? 当我仅对XPATH的后代有所了解时,在XPATH中获取值? - getting a value in XPATH when only I know something about it descendants?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM