Я работал с html5 slice и webworker, но когда он переходит к функции uploadFile, ничего не произошло. ничего не загружается
<html> <head> <title>Upload Files using XMLHttpRequest</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> </head> <body> <form id="fileuploader" enctype="multipart/form-data" method="post" action="upload.php"> <label for="fileToUpload">Select Files to Upload</label><br /> <input type="file" name="fileToUpload[]" multiple="" id="fileToUpload" onchange="fileList();"/><br /> <input type="button" onclick="sendRequest();" value="Upload" /> <!-- a place for File Listing --> <div id="fileList"> </div> </form> </body> </html> <script type="text/javascript"> function sendRequest() { var worker = new Worker("fileupload.js"); worker.onmessage = function(e) { alert(e.data); } var file = document.getElementById('fileToUpload'); for(var i = 0; i < file.files.length; i++) { worker.postMessage(file.files[i]); } }
и для файла fileupload.js
var file; var p = true; function uploadFile(blobFile, fileName, filePart, totalChunks) { var xhr = new XMLHttpRequest(); xhr.open("POST", "upload.php"+"?"+"file="+fileName + filePart, true); xhr.onload = function(e) { }; xhr.send(blobFile); } function process() { var blob = file; var originalFileName = blob.name; var filePart = 0 const BYTES_PER_CHUNK = 100 * 1024 * 1024; // 100MB chunk sizes. var realFileSize = blob.size; var start = 0; var end = BYTES_PER_CHUNK; totalChunks = Math.ceil(realFileSize / BYTES_PER_CHUNK); while( start < realFileSize ) { //self.postMessage(start); //self.postMessage("test"); var chunk = blob.slice(start, end); uploadFile(chunk, originalFileName, filePart, totalChunks); filePart++; start = end; end = start + BYTES_PER_CHUNK; } } self.onmessage = function(e) { file = e.data; /*for (var j = 0; j < e.data.length; j++) { files.push(e.data[j]); }*/ if (p) { process(); } }