c# - Azure Blob 存储上传失败

标签 c# asp.net azure azure-storage azure-blob-storage

我有一个 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# 代码引起的。

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

最佳答案

您需要修改 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>

关于c# - Azure Blob 存储上传失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12616885/

相关文章:

C# 通用和特定扩展方法组合歧义

c# - 如何将 ActionScript 中的 String 、 ByteArray 编码为 VB 或 C#

c# - 从 Int 到字符串的 LINQ 表达式转换/连接

asp.net - WSFederationAuthenticationModule v/s SessionAuthenticationModule

azure - 我无法管理 SQL Azure 中的服务器

c# - DataGridViewCheckBoxColumn 中的单元格以编程方式检查

c# - 如何创建 Windows 注册表观察器?

c# - 如何在 ASP.NET DataRepeater 控件中执行条件逻辑?

azure - 地形循环

c# - 在 .NET Core 6.0 Razor 页面应用程序中配置 Serilog 的正确方法是什么?