【问题标题】:Plupload Error -200 HTTP ErrorPlupload 错误 -200 HTTP 错误
【发布时间】:2014-07-04 23:40:41
【问题描述】:

我正在尝试将上传移动到远程服务器上。在我选择具有以下代码的文件并单击上传文件后,文件已上传,但返回错误代码:“-200”消息:“HTTP 错误”

       var uploader = new plupload.Uploader(
       {
           runtimes : 'html4, html5, flash, silverlight',
           browse_button : 'bt_browse',
           container: document.getElementById('container'),
           url : 'http://remote.com/upload.php',
           silverlight_xap_url : 'js/Moxie.xap',
           chunks_size: '20mb',
           max_retries: 3,
           filters : {
           max_file_size : '100mb'
       },
       multi_selection : true,  
       init: {
         PostInit: function() {
              document.getElementById('filelist').innerHTML = '';
              document.getElementById('bt_uploadfiles').onclick = function() {
                    uploader.start();
                    return false;
              };
         },
         FilesAdded: function(up, files) {
            plupload.each(files, function(file) {
                  //build list
    }},
         UploadProgress: function(up, file) {
         $("#progressBar"+file.id).val(Math.round(file.percent));
            if(Math.round(file.percent)==100){
                $("#progressBar"+file.id).hide();
                $("#deleteFile" + file.id).hide();
            }
         },
         FileUploaded: function(up, file, info) {
            if(file!=undefined) {
                var json = $.parseJSON(info.response);
                if(json.error == undefined)
                  moveFile(json.result, file.name, file.id);
            }
         },
         UploadComplete: function(){
         },
         Error: function(up, err) {
         }
       }
    });

我可以做些什么来避免这个错误并继续?在我的情况下,FileUploaded 和 UploadProgress 根本没有被命中 - 在我点击上传之后,我直接转到了 Error 函数。这对我来说真的很奇怪,因为在那之后我检查了它应该在的文件夹并且文件在那里。

任何帮助将不胜感激。

【问题讨论】:

  • 你有没有找到解决办法。我也面临同样的问题。有些文件已上传,有些文件尽管大小在限制范围内,但仍获得HTTP Error. (-200)。
  • 我也遇到了这个错误。低于 3Mb 的文件可以正常工作,而高于 3Mb 的文件则不能,即使 max-file-size 设置为 6mb

标签: cross-domain plupload http-error


【解决方案1】:

我在 MVC5 应用程序中使用 PlUpload 时遇到了同样的错误。问题是找不到 REST 方法。 PlUpload 使用多部分数据。下面的代码展示了如何在 WebAPI 中实现这一点

public class UploadFilesController : ApiController
{

    [HttpPost]
    [Route("UploadFiles")]
    public async Task<HttpResponseMessage> PostFormData() 
    {
        // Check if the request contains multipart/form-data.
        if (!Request.Content.IsMimeMultipartContent())
        {
            throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
        }

        string root = HttpContext.Current.Server.MapPath("~/App_Data");
        var provider = new MultipartFormDataStreamProvider(root);

        try
        {
            // Read the form data.
            await Request.Content.ReadAsMultipartAsync(provider);
            var TestId = provider.FormData.Get("TestId");
            var chunk = provider.FormData.Get("chunk");
            var chunks = provider.FormData.Get("chunks");
            var fileName = provider.FormData.Get("name");

            int chunkId = Convert.ToInt32(chunk);
            int totalChunks = Convert.ToInt32(chunks);
            Boolean isLastChunch = chunkId == totalChunks - 1;


            foreach (MultipartFileData file in provider.FileData)
            {
                //Console.WriteLine(file.Headers.ContentDisposition.FileName);
                //Console.WriteLine("Server file path: " + file.LocalFileName);
                string FileDestination = Path.GetDirectoryName(file.LocalFileName) + @"\" + fileName;

                using (FileStream fileUpload = new FileStream(file.LocalFileName, FileMode.Open))
                {
                    using (var fs = new FileStream(FileDestination, chunkId == 0 ? FileMode.Create : FileMode.Append))
                    {
                        var buffer = new byte[fileUpload.Length];
                        fileUpload.Read(buffer, 0, buffer.Length);
                        fs.Write(buffer, 0, buffer.Length);
                    }
                }
                File.Delete(file.LocalFileName);
            }

            if (isLastChunch) {
                // Do something with the completed file
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }
        catch (System.Exception e)
        {
            return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
        }

    }

【讨论】:

    猜你喜欢
    • 2014-03-26
    • 2016-11-14
    • 2016-04-22
    • 2019-09-25
    • 1970-01-01
    • 1970-01-01
    • 2015-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多