Download large files

I am an ASP.net lover working on my first job (friends site). ASP.net v4.0 using VS2010.

His company produces 3D models (using a 3D printer). A website is under construction, but can be found here . I would be the first to admit that the code was a little hasty and hacked, but my friend is quite happy with what he has.

One of the requirements is that his clients should be able to upload their model design files, which can be up to 100 MB each (or possibly more). I try my best to make it work properly.

I started by using the built-in tag <asp:FileUpload ID="FileUpload1" runat="server" />and animated gif-image, similar to the idea described in the Joe Stagner tutorial - thanks Joe, I really like your presentations.

This worked fine for a small test file, but gives no indication of download progress. So I tried to improve my solution using the ideas developed by Sunasara Imdadhusen in his code project article . My download code is as follows:

Task t = Task.Factory.StartNew(() =>
{
    byte[] buffer = new byte[UPLOAD_BUFFER_BYTE_SIZE];

    // Upload the file in chunks so that we can measure how long it is taking.
    using (FileStream fs = new FileStream(Path.Combine(newQuotePath, filename), FileMode.Create))
    {
        DateTime stopwatch = DateTime.Now;

        while (stats.Uploaded < stats.TotalSize)
        {
            int bytecount = postedFile.InputStream.Read(buffer, 0, UPLOAD_BUFFER_BYTE_SIZE);
            fs.Write(buffer, 0, bytecount);

            stats.Uploaded += bytecount;

            double dRate = UPLOAD_BUFFER_BYTE_SIZE / Math.Abs((DateTime.Now - stopwatch).TotalSeconds);
            stats.Rate = (int)(Math.Min(dRate, int.MaxValue));

            // Sleep is for debugging only!
            //System.Threading.Thread.Sleep(2000);

            stopwatch = DateTime.Now;
        }
    }
}, TaskCreationOptions.LongRunning);

Where statsis the link to the class, which is stored as a session variable and is accessible from the javascript function launched in setInterval(...)(at boot) using the PageMethod parameter:

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static UploadStatus GetFileUploadStatus()
{
    UploadStatus stats = (UploadStatus)HttpContext.Current.Session["UploadFileStatus"];

    if ((stats != null) && (stats.IsReady))
    {
        return stats;
    }
    else
    {
        return null;
    }
}

( , ). 123-Reg, . gif , , . ( IFrame), , , . - . , . , , . 16 1,6 .

, , , - (123-Reg) -.

, , , , . NeatUpload, : " NeatUpload - -", , - " decryptionKey 32 Web.config". , 123-Reg (?).

, , , ​​, dropbox, , , . , .

- .


EDIT: ... .

Dropbox ( , SkyDrive ..). , , . , MY Dropbox, ( ). , Dropbox, Sharpbox SDK ( ). , , , Dropbox ( Thread.Sleep). - 123-Reg , , .

IE9, Chrome, . , Chrome % complete . 100%, , .

MSDN HttpPostedFile: " , 256 , "

, ( )? , , Dropbox ? ?

( , , , ). , , .

+3
1

, BluImp jQuery ( -: http://blueimp.github.com/jQuery-File-Upload/) - a Max Pavlov ( , dotnet) MVC 3.

git hub https://github.com/maxpavlov/jQuery-File-Upload.MVC3. MVC 3, MVC 4 Beta. , , MVC 4, - ClientDependancy ( DLL, JS CSS ), MVC 4, MVC 3. , GitHub, , , . , . MVC 4 https://github.com/maxpavlov/jQuery-File-Upload.MVC3/wiki/MVC-4---EnableDefaultBundles.

, 2 !

+1

Source: https://habr.com/ru/post/1713076/


All Articles