7

I'm looking for good ajax upload solution.

I tried to use

1) SWFUpload (it is work fine but only for one file)

2) Jquery Ajax plugin (it's not working and it doesn't support progressbar in IE)

I'd like to ask you what solutions do you use for Uploading multiple files with progress bar?

takayoshi
  • 2,789
  • 5
  • 36
  • 56

1 Answers1

14

Personally I like Valums Ajax Upload.


UPDATE:

As requested in the comments section here's an example of how this could be used with ASP.NET MVC.

Controller:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    [HttpPost]
    public ActionResult Upload(string qqFile)
    {
        // The upload action will be called by the client control
        // for each file that was selected by the user for upload

        var path = Server.MapPath("~/App_Data");
        var file = Path.Combine(path, qqFile);
        using (var output = System.IO.File.Create(file))
        {
            Request.InputStream.CopyTo(output);
        }
        return Json(new { success = true });
    }
}

View (~/Views/Home/Index.cshtml):

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Ajax Upload demo with ASP.NET MVC</title>
    <link href="@Url.Content("~/Content/fileuploader.css")" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="file-uploader">       
        <noscript>          
            <p>Please enable JavaScript to use file uploader.</p>
            <!-- or put a simple form for upload here -->
        </noscript>         
    </div>

    <script src="@Url.Content("~/Scripts/fileuploader.js")" type="text/javascript"></script>
    <script type="text/javascript">
        var uploader = new qq.FileUploader({
            element: document.getElementById('file-uploader'),
            action: '@Url.Action("Upload", "Home")'
        });    
    </script>
</body>
</html>
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • There is no progressbar(in IE). Is it work at ASP.NET MVC? Can you post working code? – takayoshi Oct 27 '11 at 08:24
  • @takayoshi, progress bar works for me in IE. As far as your question about ASP.NET MVC is concerned, the answer is yes of course that it works with ASP.NET MVC. Ajax Upload is a client side component that work with any server side technology. It's not tied to a specific server language or implementation. – Darin Dimitrov Oct 27 '11 at 08:30
  • http://pastebin.com/aj2VNExA I use this code. I set up breakpoint on context.Response.Write("OK"); and at this point Request.Files.Count equals 0. I don't know how to access uploaded files – takayoshi Oct 27 '11 at 08:36
  • @takayoshi, I have updated my answer to show an example of how this component could be used with ASP.NET MVC. – Darin Dimitrov Oct 27 '11 at 08:51
  • @takayoshi, what about them? The client control allows you to select multiple files and the Upload action will be called for each of them independently so that you can process the files. – Darin Dimitrov Oct 27 '11 at 08:55
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/4549/discussion-between-takayoshi-and-darin-dimitrov) – takayoshi Oct 27 '11 at 09:05
  • 1
    @Darin: as always a great answer... this was pretty easy to implement. Thank you. – Leniel Maccaferri Nov 09 '11 at 21:21
  • Your link is no longer available. – Minh Nguyen Mar 24 '14 at 13:17