Azure blob存储上载失败

时间:2012-09-27 08:15:34

标签: c# asp.net azure azure-storage azure-storage-blobs

我有一个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和firefox给我一个基本的错误: 连接已重置......

编辑:当我放

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

它给了我同样的错误,所以我认为它不是由我的c#代码引起的。

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

1 个答案:

答案 0 :(得分: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>