weixin_33674976 2017-03-08 08:51 采纳率: 0%
浏览 16

创建进度条进行上传

I use this code for upload large file in asp MVC with jquery ajax.

@section scripts{

<script>
    $(document).ready(function () {
        $('#btnUpload').click(function () {
            UploadFile($('#uploadFile')[0].files);
        }
        )
    });
    function UploadFile(TargetFile) {
        // create array to store the buffer chunks
        var FileChunk = [];
        // the file object itself that we will work with
        var file = TargetFile[0];
        // set up other initial vars
        var MaxFileSizeMB = 1;
        var BufferChunkSize = MaxFileSizeMB * (1024 * 1024);
        var ReadBuffer_Size = 1024;
        var FileStreamPos = 0;
        // set the initial chunk length
        var EndPos = BufferChunkSize;
        var Size = file.size;

        // add to the FileChunk array until we get to the end of the file
        while (FileStreamPos < Size) {
            // "slice" the file from the starting position/offset, to  the required length
            FileChunk.push(file.slice(FileStreamPos, EndPos));
            FileStreamPos = EndPos; // jump by the amount read
            EndPos = FileStreamPos + BufferChunkSize; // set next chunk length
        }
        // get total number of "files" we will be sending
        var TotalParts = FileChunk.length;
        var PartCount = 0;
        // loop through, pulling the first item from the array each time and sending it
        while (chunk = FileChunk.shift()) {
            PartCount++;
            // file name convention
            var FilePartName = file.name + ".part_" + PartCount + "." + TotalParts;
            // send the file
            UploadFileChunk(chunk, FilePartName);
        }
    }
    function UploadFileChunk(Chunk, FileName) {
        var FD = new FormData();
        FD.append('file', Chunk, FileName);
        $.ajax({
            type: "POST",
            url: '/Home/UploadFile/',
            contentType: false,
            processData: false,
            data: FD
        });
    }
</script>

I need to create progress bar for this. how can i do this ?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Windows server update services
    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用
    • ¥15 Web.config连不上数据库
    • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
    • ¥15 怎么配置广告联盟瀑布流
    • ¥15 Rstudio 保存代码闪退
    • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
    • ¥50 invest生境质量模块