【问题标题】:Windows Azure : Server Error , 404 - File or directory not foundWindows Azure:服务器错误,404 - 找不到文件或目录
【发布时间】:2011-02-07 16:19:44
【问题描述】:

我想将一些大小为 35MB 的文件上传到 blob 容器。 我已经编写了将数据拆分为块并将其上传到 blob 容器并使用 PUT 形成 blob 的代码。

我测试了一些 2MB 大小 之类的文件的代码...效果很好。但是当我为一个大 MB 文件尝试它时,它给了我这个错误

Server Error
404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

当我尝试处理 6MB 大小的文件时,它给了我这个错误..

Server Error in '/' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".

<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>


Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.

<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
    </system.web>
</configuration>

谁能告诉我,如何解决这个问题...


上传 blob 的代码。

protected void ButUploadBlocks_click(object sender, EventArgs e)
        {

            // store upladed file as a blob storage
            if (uplFileUpload.HasFile)
            {
                name = uplFileUpload.FileName;
                byte[] byteArray = uplFileUpload.FileBytes;
                Int64 contentLength = byteArray.Length;
                int numBytesPerBlock = 250 *1024; // 250KB per block
                int blocksCount = (int)Math.Ceiling((double)contentLength / numBytesPerBlock);  // number of blocks 
                MemoryStream ms ;
                int length = 0;
                List<string>BlockIds = new List<string>();
                string block;
                int offset = 0;

                // get refernce to the cloud blob container
                CloudBlobContainer blobContainer = cloudBlobClient.GetContainerReference("documents");

                if (textbox.Text != "")
                {
                    name = textbox.Text + "/" + name;

                }
                // set the name for the uploading files
                string UploadDocName = name;

                // get the blob reference and set the metadata properties
                CloudBlockBlob blob = blobContainer.GetBlockBlobReference(UploadDocName);
                blob.Properties.ContentType = uplFileUpload.PostedFile.ContentType;

                for (int i = 0; i < blocksCount; i++, offset = offset + numBytesPerBlock)
                {
                    block = Convert.ToBase64String(BitConverter.GetBytes(i));
                    ms = new MemoryStream();
                    if (i == (blocksCount - 1))
                    {
                        length = (int)contentLength - offset;
                    }
                    else
                    {
                        length = numBytesPerBlock;
                    }
                    ms.Write(byteArray, offset, length);
                    ms.Position = 0;

                    blob.PutBlock(block, ms, null);
                    BlockIds.Add(block);
                }

                blob.PutBlockList(BlockIds);

                blob.Metadata["FILETYPE"] = "text";
            }
        }

【问题讨论】:

  • 您是从 ASP.NET 服务器应用程序(服务器到云)还是从桌面客户端应用程序(桌面到云)上传到 blob?你是如何上传到 blob 的?显示一些代码。

标签: c# azure blob


【解决方案1】:

我的猜测是您达到了 ASP.NET 限制...有一个最大请求大小以及一个最大请求超时。我会在 web.config 中进行建议的更改,看看有什么异常。

【讨论】:

    【解决方案2】:

    这里提到:http://robertgreiner.com/2012/08/404-error-when-uploading-large-files-in-windows-azure/

    我今天尝试使用我的 MVC 4 站点将一个 30MB 的文件上传到 Windows Azure。当文件达到 99% 时,我收到一个 404 错误,说我的上传操作无处可寻。幸运的是,我在当天早些时候成功上传了大约一半大小的文件,所以我知道该网站并没有完全崩溃。

    如果您遇到此错误,很可能您已经测试了在本地上传大文件并意识到您需要在 Web.config 中使用类似的内容才能正常工作:

    <system.web>
        <httpRuntime maxRequestLength="1073741824" requestValidationMode="2.0" />
    </system.web>
    

    然而,没有人告诉你的是,Windows Azure(即 IIS 7)在上传文件时采用了完全不同的配置设置。

    <system.webServer>
      <security>
        <requestFiltering>
          <requestLimits maxAllowedContentLength="1073741824" />
        </requestFiltering>
      </security>
    </system.WebServer>
    

    【讨论】:

      猜你喜欢
      • 2021-01-31
      • 2017-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多