Question

As it stands, my code works with HTML5 and Silverlight. However when I use Flash or HTML4, the upload form stalls. And when I check the uploaded directory, only the first file is uploaded.Screenshot

Here's my javascript for one of the uploaders:

$("#origShapeUploader").pluploadQueue({

runtimes: 'flash,html4',
url: 'upload.aspx?originals=yes', //with a query string of yes, the files being uploaded won't be given a prefix of 'MOD'
max_file_count: maxfiles,
filters: [
    { title: "Shape files", extensions: "shp,dbf,prj,shx"} //these are the only file types allowed
    ],
multi_selection: true,
flash_swf_url: '/javascript/plupload.flash.swf', //in case silverlight and html5 support doesn't exist
silverlight_xap_url: '/javascript/plupload.silverlight.xap', //silverlight browser extension


});

This is screaming server side handler issue to me, so here's my code for handling the upload, the MOD prefix is used in a different part of my program.

    if (Request.Files.Count > 0)
    {

    int chunk = Request["chunk"] != null ? int.Parse(Request["chunk"]) : 0;
    string fileName = Request["name"] != null ? Request["name"] : string.Empty;

    HttpPostedFile fileUpload = Request.Files[0];

    var uploadPath = Server.MapPath("~/uploaded-files");
    if (Request.QueryString["originals"] == "yes")
    {
        using (var fs = new FileStream(Path.Combine(uploadPath, fileName), chunk == 0 ? FileMode.Create : FileMode.Append))
        {
            var buffer = new byte[fileUpload.InputStream.Length];
            fileUpload.InputStream.Read(buffer, 0, buffer.Length);
            fs.Write(buffer, 0, buffer.Length);
        }
    }
    else
    {
        using (var fs = new FileStream(Path.Combine(uploadPath, "MOD" + fileName), chunk == 0 ? FileMode.Create : FileMode.Append))
        {
            var buffer = new byte[fileUpload.InputStream.Length];
            fileUpload.InputStream.Read(buffer, 0, buffer.Length);
            fs.Write(buffer, 0, buffer.Length);
        }


    }

}

Était-ce utile?

La solution

You need to return at least something from the back-end - OK, DONE, or json confirmation of some kind. Some Flash players have a bug where they do not recognize request completion if no output was returned from server. As for HTML4, it's just how it works.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top