Using plupload with MVC3

前端 未结 2 628
忘了有多久
忘了有多久 2020-12-30 11:59

So, I\'ve implemented plupload using flash runtime in MVC3.

It works perfectly, in the sense that it uploads using the correction Action and runs it all. However, I\

2条回答
  •  半阙折子戏
    2020-12-30 12:33

    Look here:

    $("#uploader").pluploadQueue({
             // General settings
             runtimes: 'silverlight',
             url: '/Home/Upload',
             max_file_size: '10mb',
             chunk_size: '1mb',
             unique_names: true,
             multiple_queues: false,
    
             // Resize images on clientside if we can
             resize: { width: 320, height: 240, quality: 90 },
    
             // Specify what files to browse for
             filters: [
                { title: "Image files", extensions: "jpg,gif,png" },
                { title: "Zip files", extensions: "zip" }
            ],
    
             // Silverlight settings
             silverlight_xap_url: '../../../Scripts/upload/plupload.silverlight.xap'
          });
    
          // Client side form validation
          $('form').submit(function (e) {
             var uploader = $('#uploader').pluploadQueue();
    
             // Files in queue upload them first
             if (uploader.files.length > 0) {
                // When all files are uploaded submit form
                uploader.bind('StateChanged', function () {
                   if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
                      $('form')[0].submit();
                   }
                });
    
                uploader.start();
             } else {
                alert('You must queue at least one file.');
             }
    
             return false;
          });
    

    And in Controller:

    [HttpPost]
    public string Upload(  ) {
              HttpPostedFileBase FileData = Request.Files[0];
    
              if ( FileData.ContentLength > 0 ) {
                 var fileName = Path.GetFileName( FileData.FileName );
                 var path = Path.Combine( Server.MapPath( "~/Content" ), fileName );
                 FileData.SaveAs( path );
              }
    
              return "Files was uploaded successfully!";
           }
    

    That's all...No chunk is needed in Controller...

提交回复
热议问题