Topic: How to upload files from Queue widget with HttpPost

I need some help with uploading files on my server.

@using (Html.BeginForm("Upload", "Home", FormMethod.Post, new { enctype="multipart/form-data" }))
        {
            <div id="uploader" style="width: 450px; height: 330px;">Your browser doesn't support upload.</div>
       
            <input type="submit" class="btn btn-large btn-success" value="Transfer" />
               
        }

With a hit on the submit button he needs to upload the file inside the uploader to my server but my problem is that it is always empty.

My Controller:

   public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Upload(HttpPostedFileBase file)
        {
            System.Console.WriteLine(file.FileName);
           
            return View("Index");
        }

Re: How to upload files from Queue widget with HttpPost

So you are using Queue widget... When you hit submit does it upload the files first? I do not see from your code if you launch upload process anywhere.

If you want to see your issue fixed, do not report it here, do it on - GitHub.

Re: How to upload files from Queue widget with HttpPost

With my Plupload query i upload the files:

    $(function () {
        $("#uploader").pluploadQueue({
            runtimes: 'html5, html4',
            url: '/Home/Index',
            max_file_size: '10mb',
            unique_names: true,
            multipart: true,
            multiple_queues: false,
            filters: [
                { title: "Foto's", extensions: "jpg,gif,png" },
            ],

            preinit: {
                FileUploaded: function (up, file, response) {
                    var data = response.response; //$.parseJSON(response.response);

                    $('<input>').attr({
                        type: 'hidden',
                        name: 'fileId' + data,
                        value: data
                    }).appendTo('#uploadFinishedForm');

                    if (data.error == 1) {
                        uploader.trigger("Error", { message: "'" + data.message + "'", file: file });
                        console.log('[Error] ' + file.id + ' : ' + data.message);
                        return false;
                    }
                },

                UploadComplete: function (up, files) {
                    var $container = $('.box');
                    $container.hide();
                    var $spinner = $('#spinner');
                    $spinner.show();
                    window.setTimeout(function (form) {
                        $('#uploadFinishedForm').submit();
                    }, 2000)

                },

                Init: function (up, info) {
                    $('#uploader_container').removeAttr("title");
                }
            }
        });


        $('#uploader').submit(function (e) {
            var uploader = $('#uploader').pluploadQueue();
            if (uploader.files.length > 0) {
                uploader.bind('StateChanged', function () {
                    if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
                        $('#uploader').submit();
                    }
                });

                uploader.start();
            } else {
                $('#uploadInfo').html('');
            }

            return false;
        });
});

In my Elements i see: <input type="hidden" id="upload_count" name="upload_count" value="1">

When i use my button code it returns me nothing only null unhandled object:

   public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Upload(HttpPostedFileBase uploader_count)
        {
            System.Console.WriteLine(uploader_count.FileName);
            return View("Index");
        }

Re: How to upload files from Queue widget with HttpPost

It's upload_count, not  uploader_count.

If you want to see your issue fixed, do not report it here, do it on - GitHub.