2012-09-27 106 views
5

我有一個Azure Blob存儲,我想上傳一些文件。

Index.cshtmlAzure blob存儲上傳失敗

@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#代碼造成的。

有什麼想法?非常感謝 !

回答

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> 
+0

+1。而對於真正的大文件,2分鐘的默認請求超時可能會成爲問題。 –