为什么WebClient。UploadFileAsync不处理大型文件上传?

时间:2022-04-23 07:43:05

I am uploading a file from a C# application to an ASP.Net website, both written by me so I have access to the code.

我正在从一个c#应用程序上传一个文件到一个ASP。Net网站,都是我写的,所以我可以访问代码。

But, it is working for a text file (1KB) but not for a MOV file (77MB).

但是,它适用于文本文件(1KB),而不适用于MOV文件(77MB)。

In both cases, I am using UploadProgressChanged to get the progress. The TXT file goes to 100% while the MOV file goes only till 50%. When done, I only find the TXT file saved on the server but not the MOV file.

在这两种情况下,我都使用UploadProgressChanged来获得进展。TXT文件为100%,而MOV文件仅为50%。完成后,我只找到保存在服务器上的TXT文件,而找不到MOV文件。

Why is this happening? How can I get it to work?

为什么会这样?我怎么让它工作呢?

Windows App Code - C#

Windows应用程序代码- c#

Client.UploadFileAsync(new Uri("http://localhost:xxxxxx/Default.aspx"),  "c:\\1.MOV");

Default.aspx Code - VB

违约。aspx - VB代码

Protected Sub Page_Load(...) Handles Me.Load
    If Request.Files IsNot Nothing Then
        If Request.Files.Count > 0 Then
            Request.Files(0).SaveAs(Server.MapPath("~/1.mov"))
            Response.Write("File saved at: " + Server.MapPath("~/1.mov"))
        Else
            Response.Write("At least one file should be sent")
        End If
    Else
        Response.Write("No file received")
    End If
End Sub

2 个解决方案

#1


3  

You can change the default limit (4mb) in a localized way by dropping a web.config file in the directory where your upload page lives. That way you don't have to allow huge uploads across your whole site(doing so would open you up to a certain kinds of attacks).

您可以通过删除web以本地化的方式更改默认限制(4mb)。在上传页面所在的目录中配置文件。这样你就不需要在整个站点上允许大量的上传(这样做会让你受到某种类型的攻击)。

Here's an example from a production app. This one is set for 100mb:

这是一个生产应用的例子。这个设置为100mb:

<configuration>
  <system.web>
  <httpRuntime maxRequestLength="100000" executionTimeout="600" />
  </system.web>
</configuration>

#2


0  

Exception throws when the specified value is less than 1 kilobytes and greater than 4194304 kilobytes (4 GB).

当指定的值小于1千字节且大于4194304千字节(4 GB)时抛出异常。

#1


3  

You can change the default limit (4mb) in a localized way by dropping a web.config file in the directory where your upload page lives. That way you don't have to allow huge uploads across your whole site(doing so would open you up to a certain kinds of attacks).

您可以通过删除web以本地化的方式更改默认限制(4mb)。在上传页面所在的目录中配置文件。这样你就不需要在整个站点上允许大量的上传(这样做会让你受到某种类型的攻击)。

Here's an example from a production app. This one is set for 100mb:

这是一个生产应用的例子。这个设置为100mb:

<configuration>
  <system.web>
  <httpRuntime maxRequestLength="100000" executionTimeout="600" />
  </system.web>
</configuration>

#2


0  

Exception throws when the specified value is less than 1 kilobytes and greater than 4194304 kilobytes (4 GB).

当指定的值小于1千字节且大于4194304千字节(4 GB)时抛出异常。