尝试解析长文件的xhr响应文本时出错

时间:2013-09-02 19:23:58

标签: jquery asp.net file file-upload fine-uploader

我正在使用Jquery fineUploader上传我正在获取的文件

404 - 找不到文件或目录。

当上传超过30MB的文件时,小于30MB的小文件工作正常。

在火灾中,错误显示:

[FineUploader] Error when attempting to parse xhr response text
(SyntaxError: JSON.parse: unexpected character)

 [FineUploader] Caught exception in 'onValidate' callback -TypeError: file is undefined
 log(a="[FineUploader] Caught e...rror: file is undefined", b="error")

enter image description here

下面的

是我的处理程序代码:

 public void ProcessRequest(HttpContext context)
{
    string directoryID = context.Request["dId"];
    var response = new AjaxResponse { ResponseData = "" };

    if (!string.IsNullOrEmpty(directoryID))
    {
        int spaceID = 0;
        int dirID = Convert.ToInt32(directoryID);

        string directoryPhysicalPath = "D:\\Files\\";
        string fileName = context.Request["qqfile"];

        string saveLocation = Path.Combine(directoryPhysicalPath, fileUniqueName);
        if (!Directory.Exists(directoryPhysicalPath))
        {
            Directory.CreateDirectory(directoryPhysicalPath);
        }

        DateTime currentDateTime = DateTime.UtcNow;

        var file = new File();
        try
        {
            int bytesRead = 0;
            Stream inputStream = context.Request.InputStream;
            byte[] buffer = new byte[inputStream.Length];

            try
            {
                using (var fileStream = new FileStream(saveLocation, FileMode.Create))
                {
                    do
                    {
                        bytesRead = context.Request.InputStream.Read(buffer, 0, buffer.Length);
                        fileStream.Write(buffer, 0, bytesRead);
                    } while (bytesRead > 0);
                }

                file = new File
                {
                    FileName = fileName
                };

               //Add to DB Here

            }
        }
        catch (PathTooLongException ex)
        {
            response.IsError = true;
            response.ResponseMessage = ex.Message;
        }

        File f = //Get data from DB here;

        response.ResponseData = f;

        context.Response.Write(new JavaScriptSerializer().Serialize(response));

    }
}

1 个答案:

答案 0 :(得分:0)

我已解决此问题,将以下设置放在<system.webServer>部分

下的web.config中
  <security>
    <requestFiltering >
        <requestLimits maxAllowedContentLength="2000000000"/>
    </requestFiltering>
</security>