javascript - cannot upload files and vars with xhr2 and web workers -
i try create code upload files using xhr2 , web workers. thought should use web workers , if file big, web page not freeze.
this not working 2 reasons, never used web workers before, , want post server file , vars @ same time, same xhr. when vars mean name of file, , int.
heres got
client side
//create worker var worker = new worker('fileupload.js'); worker.onmessage = function(e) { alert('worker says '+e.data); } //handle workers error worker.onerror =werror; function werror(e) { console.log('error: line ', e.lineno, ' in ', e.filename, ': ', e.message); } //send stuff worker worker.postmessage({ 'files' : files, //img or video 'name' : nameofthepic, //text 'id':imageinsertid //number });
inside worker (fileupload.js file)
onmessage = function (e) {var name=e.data.name; var id=e.data.id ; var file=e.data.files; //create var catch anser of server var datax; var xhr = new xmlhttprequest(); xhr.onload = function() { if (xhr.status == 200) {datax=xhr.response;} else { datax=525;}//actually, whatever, give value }; xhr.open('post', 'upload.php'); xhr.send(file,name,id); //i tried xhr.send('file=file&name=name&id=id'); , still nothing //i tried text/int xhr.send('name=name&id=id'); , still nothing
i confused. cannot send server. no feedback worker. dont know if data send fileupload.js. server side not insert.
is possible, sending files , text @ same time? missing?
i need pass text , int along file, server side not upload file, insert database int , text, if file uploaded succesfully. easy formdata , xhr, but, putting web workers in middle, cant right.
also, can use transferable objects speed things up? transferable objects supported in major browsers?
thanks in advance
Comments
Post a Comment