cordova - Audio file uploading to server using phonegap and receiving result in android -
i trying upload audio file server every alternate upload gets failed.
e/filetransfer(10242): {"target":"http:\/\/abc:8080\/foldername\/foldername\/test.php?" , "source":"file:\/\/\/storage\/sdcard0\/voice.wav","code":3} e/filetransfer(10242): java.io.eofexception
my code:
var gotfilesystem = function(filesystem) { filesystem.root.getdirectory(dirname, { create : true }, function(datadir) { fileuri = datadir.fullpath; fileuri = fileuri + '/' + filename; var options = new fileuploadoptions(); options.filekey = "file"; options.filename = fileuri.substr(fileuri.lastindexof('/') + 1); options.mimetype = filemime; $.mobile.showpageloadingmsg(); var ft = new filetransfer(); ft.upload(fileuri, encodeuri(url), win, fail, options); $.mobile.hidepageloadingmsg(); }, dirfail); };
instead of getting directory (getdirectory) file directly using (getfile) method.
var filepath = "myfolder/myfile.mp3"; var fileuploadurl = "fileupload.jsp"; window.requestfilesystem(localfilesystem.persistent, 0,function(fs){ fs.root.getfile(filepath,{create: false, exclusive: false}, function(mediafile){ var ft = new filetransfer(); var fpath = mediafile.fullpath; var fname = mediafile.name; var options = new fileuploadoptions(); options.filekey = "mediafile"; options.filename = fname; options.mimetype = "audio/mpeg"; ft.upload(fpath, fileuploadurl, function(result) { console.log('upload success: ' + result.responsecode); console.log(result.bytessent + ' bytes sent'); }, function(error) { console.log('error uploading file ' + fpath + ': ' + error.code); },options); ft.abort(); }, null); } , null);
`
Comments
Post a Comment