Azure Blob 存储上传失败

6
我有一个 Azure Blob 存储,我想上传一些文件。

Index.cshtml
@using (Html.BeginForm("File_post", "MyController", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <div class="editor-label">
    <p>
        <input type="file" name="file" />
    </p>
        <input type="submit" value="Upload" />
    </div>
}

MyController.cs

public ActionResult File_post(HttpPostedFileBase file)
{
    CloudBlobContainer blobContainer = Initialize(); // This Initialize my blobContainer
    CloudBlockBlob blob;
    blob = blobContainer.GetBlockBlobReference("myfile");
    blob.UploadFromStream(file.InputStream);
    Return("Index");
}

我测试了一个大小为3.5Mo的文件,它能够正常运行,即使是20Mo的文件也可以。现在我尝试使用33Mo的文件,但火狐浏览器给出了基本错误提示:

编辑:当我输入

public ActionResult File_post(HttpPostedFileBase file)
{
    Return("Index");
}

我遇到了同样的错误,所以我认为这不是由我的C#代码引起的。

有什么想法吗?非常感谢!

1个回答

7
您需要修改web.config文件以允许在ASP.NET和IIS中上传大文件(以下示例将允许上传50MB的文件):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
        <httpRuntime maxRequestLength="51200" />
    </system.web>
    <system.webServer>
        <security>
            <requestFiltering>
                <requestLimits maxAllowedContentLength="51200000" />
            </requestFiltering>
        </security>
    </system.webServer>
</configuration>

对于非常大的文件,默认请求超时时间为2分钟可能会成为一个问题。+1。 - Alexei Levenkov

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接