简体   繁体   English

使用Web API进行大文件上载

[英]Large File Upload using Web API

I have a winforms application that sends a multipart file to webAPI. 我有一个winforms应用程序,它将一个multipart文件发送到webAPI。 It works fine for servers here in the office. 它适用于办公室中的服务器。 But the same isnt working when the server is in UTAH. 但是当服务器在UTAH时,同样不起作用。 For small files, it is OK. 对于小文件,没关系。 But not for large files. 但不适用于大文件。

Here is the code where we use for uploading: 以下是我们用于上传的代码:

if (!Request.Content.IsMimeMultipartContent())
            throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);

        // Save document to disk
        String rootPath = _repository.Document_AddDirectory(documentID, User);
        FileStreamProvider provider = new FileStreamProvider(_repository, rootPath, documentID, User);

        await Request.Content.ReadAsMultipartAsync(provider)
            .ContinueWith(t =>
            {
                if (t.IsFaulted || t.IsCanceled)
                {
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            });

Here are some web.config settings you might check on your server in Utah that could be the cause of a large file size failing on one server while working on another. 以下是您可能在犹他州的服务器上检查的一些web.config设置,这些设置可能导致在另一台服务器上处理大文件大小时失败。

httpRuntime maxRequestLength - The size limit for a request stream. httpRuntime maxRequestLength - 请求流的大小限制。 The default is 4096 (4mb). 默认值为4096(4mb)。

httpRuntime executionTimeout - The number of seconds before a request is automatically shut down httpRuntime executionTimeout - 请求自动关闭之前的秒数

this has to do with HttpClient. 这与HttpClient有关。 I used a filestreamcontent , which delayed the process. 我使用了一个filestreamcontent,它延迟了这个过程。 So, I changed to Bytearraycontent and moved all the process to async version. 所以,我改为Bytearraycontent并将所有进程转移到异步版本。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM