java - Posting photo from Cordova to Spring Web Service -


i writing proof of concept app consists of sencha touch/ cordova hybrid application accesses phones camera api, takes picture , uploads spring server. have got the mobile application jamming properly. have managed take picture having issues posting spring end. when debug server can see app hitting web service correctly, image byte[] seems blank. debugged on client side using android logcat , there image being sent client side. think problem lies webservice receiving posted image.

my basic client side code follows :

  function onphotourisuccess(imageuritoupload){     var url=encodeuri("http://192.168.2.4:8080/app/api/rest//uploadimage/");      var params = new object();     params.your_param_name = "something";  //you can send additional info file      var options = new fileuploadoptions();     options.filekey = "the_name_of_the_image_field"; //depends on api     options.filename = imageuritoupload.substr(imageuritoupload.lastindexof('/')+1);     options.mimetype = "image/jpeg";     options.params = params;     options.chunkedmode = true; //this important send both data , files      var headers={'authorization':'token_based_authentication '+ localstorage.getitem('token')};     options.headers = headers;      var ft = new filetransfer();     console.log("donovan");     console.log("image uri" + imageuritoupload)     ft.upload(imageuritoupload, url, win, fail, options, true);  }  function win(r) {     console.log("code = " + r.responsecode.tostring()+"\n");     console.log("response = " + r.response.tostring()+"\n");     console.log("sent = " + r.bytessent.tostring()+"\n");     alert("code slayer!!!"); }  function fail(error) {     alert("an error has occurred: code = " + error.code); }  ext.define('photobomb.view.main', {     extend: 'ext.panel',     xtype: 'main',     requires: [         'ext.button',         'ext.img'     ],     config: {         layout: {             type:"vbox",             pack:"center",             align:"center"         },         items: [             {                 xtype: "image",                 src: "http://placehold.it/200x200",                 width: 200,                 height: 200             },             {                 xtype: "button",                 text: "photo",                 handler: function()                 {                     console.log('handler launching camera');                     navigator.camera.getpicture(onphotourisuccess, onfail,                         {                             quality: 40,                             destinationtype:camera.destinationtype.file_uri,                             encodingtype : navigator.camera.encodingtype.jpeg,                             targetwidth: 500,                             targetheight: 500,                             savetophotoalbum: 1                         });                      function onfail(){                         ext.msg.alert(message);                         console.log(message);                     }                      function refreshimages()                     {                         console.log('image gallery refreshed');                     }                  }             }         ]     } }); 

my basic spring webservice follows :

path("/uploadimage/") @produces("application/json") @consumes("*/*") public interface imagepostwebservice {     /**      * web service handles tokens      */         @post         string postpicture(inputstream streame); } 

and implementation

   @override     public string postpicture(inputstream image) {         byte [] images;         try {             images = ioutils.tobytearray(image);         }         catch (exception e) {             return "mother trucker";         }          boolean empty = true;         (byte b : images) {             if (b != 0) {                 empty = false;             }         }         if (empty) {             return "empty";         }                 log.info("image upload webservice hit");        log.info(arrays.tostring(images));          employee employee = contextbeanservice.getloggedonemployee();         uploadrequestdto uploadrequest = new uploadrequestdto(employee.getid(), documenttype.client_mugshot,                 "new.jpg", "image/jpeg");         uploadrequest.setextension("jpg");         try {         documentcrudmappingservice.createdocument(documenttype.client_mugshot, uploadrequest, images,                 employee.getid());         } catch (ioexception ioe) {          }          return "done";     } 

when run application , debug server side can see hitting webservice, when print out byte[] received follows : [115, 111, 109, 101, 116, 104, 105, 110, 103], isnt expect image samsung s4mini camera phone, think missing regards uploading image cordova spring webservice. appreciated !

the source of problem had made incorrect assumption using spring webservice, when in fact using java web services. once discovered pretty straight forward sort problems out. in fact missing form paramater webservice never expecting image. fix web service interface follows :

import javax.ws.rs.*;  @path("/uploadimage/") @produces("application/json") @consumes("*/*") public interface imagepostwebservice {     /**      * web service handles tokens      */         @post         string postpicture(@formparam("image") string image); }   

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -