Spring Rest API - multiple threads -
i have developed spring rest api takes multipart file in request , uploading them aws s3 location. process taking time , client has wait whole process completed.
i not want client wait upload process complete want send image urls in response.
can send image urls in response , open thread uploading images s3?
you can achieve via springs' deferredresult leverages servlet 3.0 async capabilities.
your controller below (originally posted here tomasz)
@requestmapping("/upload") @responsebody public deferredresult<string> upload() { final deferredresult<string> deferredresult = new deferredresult<>(); runinotherthread(deferredresult); return deferredresult; } private void runinotherthread(deferredresult<string> deferredresult) { // call aws s3 upload , collect response deferredresult.setresult("file uploaded"); }
refer tutorial complete working example.
Comments
Post a Comment