Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the technology of uploading large files with html5

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "html5 how to achieve large file upload technology", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "html5 how to upload large file technology" this article.

The code is as follows:

Document add Files Function get_filemd5sum (ofile) {var file = ofile Var tmp_md5 Var blobSlice = File.prototype.slice | | File.prototype.mozSlice | | File.prototype.webkitSlice, / / file = this.files [0], chunkSize = 2 * 1024 * 1024, / / Read in chunks of 2MB chunks = Math.ceil (file.size / chunkSize), currentChunk = 0, spark = new SparkMD5.ArrayBuffer () FileReader = new FileReader () FileReader.onload = function (e) {/ / console.log ('read chunk nr', currentChunk+ 1,' of', chunks); spark.append (e.target.result); / / Append array buffer currentChunk++; var md5_progress = Math.floor ((currentChunk / chunks) * 100) Console.log (file.name + "processing, please wait a moment," + "completed" + md5_progress + "%"); var handler_info = document.getElementById ("handler_info"); var progressbar = document.getElementsByClassName ("progressbar") [0] Handler_ in [XSS _ clean] = file.name + "processing, please wait a moment," + "completed" + "%" progressbar.value = md5_progress; if (currentChunk

< chunks) { loadNext(); } else { tmp_md5 = spark.end(); console.log(tmp_md5) handler_info[xss_clean] = file.name + "的MD5值是:" + tmp_md5; } }; fileReader.onerror = function() { console.warn('oops, something went wrong.'); }; function loadNext() { var start = currentChunk * chunkSize, end = ((start + chunkSize) >

= file.size)? File.size: start + chunkSize; fileReader.readAsArrayBuffer (blobSlice.call (file, start, end));} loadNext ();} var uploadfile = document.getElementById ('fileinput') uploadfile.onchange = function (e) {var file = this.files [0] If (! file) {alert ('Please select a file!') ; return false;} get_filemd5sum (file)} these are all the contents of the article "how to upload large files by html5". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report