HTML 5 文件上传
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4162102/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Html 5 File upload
提问by Mika Darlow
I've been trying to get Html 5 file uploading to work. I just don't seem to "get it". So rather than tell you about all the problems I'm facing I was wondering if someone has already nicked this in the bud and would be willing to help.
我一直在尝试让 Html 5 文件上传工作。我只是似乎没有“明白”。因此,与其告诉你我面临的所有问题,我想知道是否有人已经在萌芽状态下解决了这个问题并且愿意提供帮助。
Nice to have features would be 1. File upload progress 2. Time left 3. Some sort of confirmation once upload has completed
很高兴有功能 1. 文件上传进度 2. 剩余时间 3. 上传完成后的某种确认
回答by Konga Raju
Uploading large file is equal to grabbing maximum resources from CPU and putting the user agent in block state, so we need to avoid these two things, for that we have to upload the large file as multiple parts(chunks), so we have to slice the file and we have to upload in background.
上传大文件就等于从CPU上抢了最大的资源,让用户代理处于阻塞状态,所以我们要避免这两件事,因为我们必须把大文件分成多个部分(块)上传,所以我们必须切片文件,我们必须在后台上传。
HTML5 introduced some APIs, useful APIs for uploading large file are webworkers and File API. These two are helpful while uploading large file, we have to upload slice the file at client side to make the file as chunks then we need to upload at background to increase the performance of CPU.
HTML5 引入了一些 API,用于上传大文件的有用 API 是 webworkers 和 File API。这两个在上传大文件时很有帮助,我们必须在客户端上传文件切片以使文件成为块然后我们需要在后台上传以提高CPU的性能。
For slicing the File API has slice call
对于切片文件 API 有切片调用
var chunk=file.webkitSlice(start,stop)||file.mozSlice(start,stop);
we have to process the uploading in background Using Webworkers to free the user agent.
我们必须在后台处理上传使用 Webworkers 来释放用户代理。
var worker=new worker('worker.js');
worker.postMessage(FileList);