javascript - how to read audio file in fire fox using file reader class -
savebutton.onclick = function(e) { var filename= file.name; console.warn("file name " +filename); //alert("hello"); var audiotype = "audio/*"; //console.warn("audiotype " +audiotype); if(filename.type.match(audiotype)) { console.warn("audiotype " +audiotype); var reader=new filereader(); console.warn("file reader object " +reader); read.onload=function(e) { var rowdata=reader.result; console.warn("file reader object row data " +rowdata); } reader.readasbinarystring(filename); } }
here on save button event getting audio file name using file.name.now want read in buffer because want upload file on server.so want read using file reader class.but here not getting output.can 1 plzz me figure out problem in code.
very broad solution, supposing using post request upload file , server accepting post request.
var myfile; var myform = new formdata(); myform.append('nameofthefile', myfile, 'nameofthefilewithextension'); var xhr = new xmlhttprequest(); xhr.open('post', 'http://foo.com/submitform.php'); xhr.send(myform);
brief explanation; have file object called myfile , want upload server, need make request xmlhttprequest , append formdata field it. easier way using formdata object, append file , send formdata xmlhttprequest.