javascript - Sending Audio file/blob from UI to Servlet for saving at server. -
we trying send our audio file ui side using following code
var url = (window.url || window.webkiturl).createobjecturl(blob); var link = document.getelementbyid("save"); link.href = url; link.download = filename || 'output.wav'; var fd = new formdata(); fd.append('fname', 'sample1.wav'); fd.append('data', blob); $.ajax({ type: 'post', url: 'audiototext', data: fd, processdata: false, contenttype: "audio/wav" });
but unable process in servlet. can me javascript code send audio file servet , servlet code save audio fie in servlet. in advance.
good day
you can use plugin fileupload
https://github.com/blueimp/jquery-file-upload
there quite full instruction how use spring , ajax:
http://krams915.blogspot.ru/2012/06/file-upload-with-spring-and-jquery-part_2793.html (from wiki of plugin)
quick tutorial (don't forget include plugin)
html code:
<label>name</label> <form name="fileupload" method="post" class="newsongupload" action="upload.new.song" id="uploadnewfile"> <!--in action - url --!> <input type="text" name="songname"> <i class="glyphicon glyphicon-plus"></i> <input type="file" name="files" id="upload-new-document" accept="your accept here"> </form> </div>
js code:
$(function () { $('.newsongupload').fileupload({ multipart: true, datatype: 'json'//actually enough plugin works //you can write happen after loading in done:yourcode , accept in accept:your types }) });
java spring code:
@requestmapping(value = {"/upload.new.song"}, method = requestmethod.post) public @responsebody hashmap<string, string> uploadnewsong(httpservletresponse response, @requestparam("file") multipartfile file){ //your code file here can save database or file system file.getbytes() function }
i hope it'll you
Comments
Post a Comment