通过带有404,TypeMismatchError或“没有足够的存储空间来完成此操作"的jQuery ajax错误发送大JSON. [英] Sending large JSON via jQuery ajax errors with 404, TypeMismatchError, or "Not enough storage is available to complete this operation"

查看:71
本文介绍了通过带有404,TypeMismatchError或“没有足够的存储空间来完成此操作"的jQuery ajax错误发送大JSON.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ASP.NET Web应用程序来上传文件,但是当上传大小变大时,我遇到了一个问题.

I'm working on an ASP.NET web application for uploading files and I'm having an issue when the upload size gets large.

我正在将JSON字符串发送到C#WebMethod.JSON包含文件(base64)和有关该文件的元数据(由用户输入).

I'm sending a JSON string to a C# WebMethod. The JSON contains files (base64) and metadata about the file (input by the user).

这是我的JSON的结构:

Here's the structure of my JSON:

{
    "files" : 
    [
        {
            "filename" : "test.txt",
            "fileBase64" : "base64string",
            "customMetadata" : "bla bla bla"
        },
        {
            "filename" : "test2.txt",
            "fileBase64" : "base64string",
            "customMetadata" : "bla bla bla"
        }
    ]
}

UploadInput类:

UploadInput class:

public class UploadInput
{
    public string filename { get; set; }
    public string fileBase64 { get; set; }
    public string customMetadata { get; set; }
}

Web方法签名:

[WebMethod]
public static string UploadFiles(List<UploadInput> files) { ... }

当JSON小于约30MB时,一切正常.

When the JSON is below ~30MB, everything works fine.

当JSON达到30MB左右时,出现404 not found错误.(IE,Chrome和Filefox)

When the JSON gets around 30MB, I get a 404 not found error. (IE, Chrome, and Filefox)

当JSON达到50MB左右时,我收到TypeMismatchError.(仅IE)

When the JSON gets around 50MB, I get a TypeMismatchError. (Just IE)

当JSON达到60MB左右时,出现没有足够的存储空间来完成此操作"错误.(仅IE)

When the JSON gets around 60MB, I get a "Not enough storage is available to complete this operation" error. (Just IE)

我捕获了Web流量,并且在遇到TypeMismatchError或没有足够的存储空间来完成此操作"错误时未发送请求,因此它们必须在客户端上发生.

I captured the web traffic and the request isn't being sent when I encounter the TypeMismatchError or the "Not enough storage is available to complete this operation" error, so they must be occurring on the client.

这是我的JavaScript:

Here's my JavaScript:

function uploadFiles() {
    $.blockUI({ message: null });

    var formData = {
        "files" : _files
    }

    $.ajax({
        url: 'Images.aspx/UploadFiles',
        type: 'POST',
        data: JSON.stringify(formData),
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        success: function (result) {
            // remove the upload rows
            $(".upload-row").remove();

            // clear the _files array
            _files = [];
            updateCurrentUploadSize();

            // display the result
            displayUploadResults(result.d);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            // display the error
            $("#upload-results-div")
                .html("Request: " + XMLHttpRequest.toString()
                    + "\n\nStatus: " + textStatus 
                    + "\n\nError: " + errorThrown);
        },
        complete: function () {
            $.unblockUI();
        }
    })
}

错误函数的参数没有提供任何详细信息,只有404,TypeMismatchError和没有足够的存储空间来完成此操作".我有办法获取有关错误的更多信息吗?

The arguments to the error function aren't giving me any detailed information, just 404, TypeMismatchError, and "Not enough storage is available to complete this operation". Is there a way for me to obtain more information on the errors?

我已经在Web.config文件中设置了 maxJsonLength ="100000000" maxRequestLength ="100000000" .还有其他设置会阻止发送请求吗?

I already set maxJsonLength="100000000" and maxRequestLength="100000000" in my Web.config file. Are there any other settings that would prevent the request from being sent?

任何想法和建议都会有所帮助,我完全停留在这一点上.

Any ideas and suggestions would be helpful, I'm completely stuck on this one.

谢谢.

推荐答案

默认

The default maxAllowedContentLength is 30000000, which is why I got the 404 error when the upload size was more than 30MB. I added the following to my Web.config file and I no longer get the 404 error.

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

这篇关于通过带有404,TypeMismatchError或“没有足够的存储空间来完成此操作"的jQuery ajax错误发送大JSON.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆