Windows Azure:服务器错误,404 - 未找到文件或目录

发布于 2024-08-28 23:16:09 字数 4037 浏览 2 评论 0原文

我想将一些大小为 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";
            }
        }

I want to upload some files of size 35MB on to the blob container.
I have coded for splitting the data into blocks and upload it on to the blob container and form a blob using PUT.

I tested the code for some files of Size 2MB or something... It worked well. But When I tried it for a large MB file, its giving me this error

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.

when I tried it for files of size 6MB, it gives me this error..

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>

Can anyone tell me, How to solve this...


The code for uploading the 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";
            }
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瞄了个咪的 2024-09-04 23:16:09

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

My guess would be that you're hitting an ASP.NET limit... there's a max request size as well as a max request timeout. I'd make the change suggested in web.config and see what the exception is.

别靠近我心 2024-09-04 23:16:09

如此处所述: 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>

as mentioned here: http://robertgreiner.com/2012/08/404-error-when-uploading-large-files-in-windows-azure/

I tried to upload a 30MB file into Windows Azure today using my MVC 4 site. When the file got to 99% I got a 404 error saying that my upload Action was nowhere to be found. Fortunately, I successfully uploaded a file earlier in the day at about half the size, so I knew the site wasn’t completely broken.

If you are experiencing this error, chances are you already tested uploading large files locally and realized that you need something like this in your Web.config for everything to work:

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

However, what nobody tells you, is that Windows Azure (i.e. IIS 7) looks at a completely different configuration setting for uploading files.

<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="1073741824" />
    </requestFiltering>
  </security>
</system.WebServer>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文