javascript - Mutipart File upload using Angularjs and Spring -


i'm trying upload files using angularjs rest api exposed via spring :

this controller:

@requestmapping(value = util/images/{partyid},         method = requestmethod.post) public jsonnode uploadpartyrefimage(@requestpart("file") multipartfile inputfile,                                     @pathvariable string partyid){     objectmapper objectmapper = new objectmapper();     jsonnode jnode = null;     try {         string[] fileinput = ((diskfileitem) ((commonsmultipartfile) inputfile).getfileitem()).getname().split("\\.");         path storagepath= paths.get(uploadpath);         filesystemutil.writefile(storagepath,inputfile.getinputstream());         jnode = objectmapper.readtree("{\"type\":\"" + "success" + "\",\"filestorepath\":\"" + pathstring + "\"}");     } catch (exception exapi) {         logger.error("error uploading party attached image "+ exapi);     }     return jnode; } 

this api works fine when used via postman. postman call:

enter image description here

but when calling through angular throws exception:

angular service:

function uploadimage(formdata,partyrefid){         console.log(utilservice);         if (utilservice) {             return utilservice.request({                 method: "post",                 resource: "/images/" + partyrefid,                 headers: { 'content-type': undefined},                 processdata: false,                 transformrequest: angular.identity,                 mimetype: "multipart/form-data",                 cache: false,                 data: formdata             })                 .then(function (data) {                     if (data) {                         return getresultdatafromresponse(data);                     }                 }, function (error) {                     console.log('error invoking document upload service', error);                 });         }     } 

angular controller:

$ctrl.uploaddocument = function () {                 var formdata = new formdata();                 formdata.append("file", k.documentfile.lffile);                 var filename = "party01" + k.documentreference;                 fbeonboardingwizardservice.uploadimage(formdata,filename)                     .then(function (data) {                     if(data.type == "success")                        console.log(data.filestorepath);                    },function (error) {                         console.log(error);                    }); }; 

error in jboss:

02:06:25,442 warn  [org.springframework.web.servlet.mvc.support.defaulthandlerexceptionresolver] (http--0.0.0.0-8080-4) handler execution resulted in exception: content type 'null' not supported 

if update content-type "multipart/form-data" in angular service

error in jboss:

servlet.service() servlet appservlet threw exception: org.apache.commons.fileupload.fileuploadexception: request rejected because no multipart boundary found 


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -