Frage

I'm need to implement next page:

User click on button Upload file, select file and uploading it on server. After uploading file will be processed by converter. Converter can return percentage of conversion. How to implement continuous progress bar on page (progress = upload progress + convert progress)?

I'm using PlUpload - this tool can return percentage of uploading file to server, but I can't override returning percentage.

That my upload action:

   public ActionResult ConferenceAttachment(int? chunk, string name, Identity cid)
    {
        var fileUpload = Request.Files[0];

        var tempfolder = Path.GetTempFileName().Replace('.', '-');
        Directory.CreateDirectory(tempfolder);
        var fn = Path.Combine(tempfolder, name);

        chunk = chunk ?? 0;
        using (var fs = new FileStream(fn, 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);
        }

        // CONVERTING ....

        return Content("OK", "text/plain");
    }

Which architecture solution can solve my problem? Or which JS upload library?

War es hilfreich?

Lösung

You must use some kind of Real-Time connection or a Streaming to do this.

1) Using SignalR you can create a Hub to notificate the client about the progress, easy to implement and powerfull.

Learn About ASP.NET SignalR

2) You can adapte this example about PushStreamContent to send the progress while you are converting:

Asynchronously streaming video with ASP.NET Web API

Andere Tipps

You can set buffer size as much as you want. But, I would say to upload 8kb data of file at a time & meanwhile start streaming conversion process asynchronously. But, for smooth progress again what kind of file you wanna upload?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top