java - Receiving binary image from client and saving it on server side -
i working on spring-mvc application clientside using html2canvas function take screenshot , send server farther processing , conversion. posting code html2canvas below. have controller mapping can read byte array, unable pass server, maintain getting error(also displayed below). finally, receive binary image , save in server side. kindly allow me know.
error :
info: error parsing http request header note: farther occurrences of http header parsing errors logged @ debug level.
html2canvas code :
$(".description").click(function(){ html2canvas($('body'), { onrendered: function(canvas) { var img = canvas.todataurl("image/png"); $('<img>',{src:img}).appendto($('#canvas-image')); } });
controller code :
@requestmapping("/convertbase/{id}") public string convertbase(@modelattribute("notices") notes p,@pathvariable("id") byte[] id,model model){ byte[] info = org.apache.commons.codec.binary.base64.decodebase64(id); seek { fileoutputstream imageoutfile = new fileoutputstream("/home/akshay/check.png"); imageoutfile.write(data); imageoutfile.close(); } grab (filenotfoundexception e) { e.printstacktrace(); } grab (ioexception e) { e.printstacktrace(); } homecoming "redirect:/note/listing"; }
what doing wrong, pointers helpful. give thanks time.
new controller :
@requestmapping(value = "/convertbase/{id}",method = requestmethod.post) public string convertbase(@requestbody string body){ byte[] b = body.getbytes(); byte[] info = org.apache.commons.codec.binary.base64.decodebase64(b); seek { fileoutputstream imageoutfile = new fileoutputstream("/home/akshay/check.png"); imageoutfile.write(data); imageoutfile.close(); } grab (filenotfoundexception e) { e.printstacktrace(); } grab (ioexception e) { e.printstacktrace(); } homecoming "redirect:/note/listing"; }
ajax request :
$(".description").click(function(){
html2canvas($('body'), { onrendered: function(canvas) { var img = canvas.todataurl("image/png"); $('<img>',{src:img}).appendto($('#canvas-image')); $.ajax({ url: '../convertbase', type: 'post', data:{image:img} }); } });
you trying pass image in url, right? so, in case url can long , server can not able parse such request. regular solution send info using post in request body.
java spring html2canvas
No comments:
Post a Comment