File upload [angular4 with springboot]




Asked on June 06, 2018
Hello,

I have refered this link for file upload[angular4 with springboot] :
http://javasampleapproach.com/frontend/angular/angular-4-uploadget-multipartfile-tofrom-spring-boot-server#comment-7803

I have worked on code which i have given link above. it has worked for me when i run it independently.
but when i apply this same code in my project [ angular4 with spring boot micro services] it was giving error related to X-XSRF TOKEN as follows,
[{“timestamp”:1528350053314,”status”:403,”error”:”Forbidden”,”message”:”Invalid CSRF Token ‘null’ was found on the request parameter ‘_csrf’ or header ‘X-XSRF-TOKEN’.”,”path”:”/core-location/post”}] .


Here i need to pass some headers like X-XSRF TOKEN so passed headers as follows,


formdata.append(‘file’, file);
formdata.append(‘Content-Type’, ‘application/json’);
formdata.append(‘Accept’, application/json);
formdata.append(‘X-XSRF-TOKEN’, this._cookieService.get(“XSRF-TOKEN”));

const req = new HttpRequest(‘POST’,’http://localhost:8088/core-location/post’, formdata, {

reportProgress: true,
responseType: ‘text’
});
return this.http.request(req);
}
}

After passing headers also its giving me same error and also file is not going to backend[springboot]. How to pass headers in the request.


please provide solution for this.


Thanks and Regards
Shakti Lohar



Write Answer











©2024 concretepage.com | Privacy Policy | Contact Us