I am using spring mvc, hateoas. I have a controller action that looks like
@RequestMapping(value = "/images/{userId}/{publicUrl}/{fileName:.+}", method = RequestMethod.GET) public void image(@PathVariable Integer userId, @PathVariable String publicUrl, @PathVariable String fileName, HttpServletRequest request, HttpServletResponse response) throws Exception { try(HellodoxAws aws = haws;){ ..... ..... response.setContentType(image.getObjectMetadata().getContentType()); response.setHeader("ETag",image.getObjectMetadata().getETag()); response.setHeader("Cache-Control",image.getObjectMetadata().getCacheControl()); response.setHeader("Last-Modified",image.getObjectMetadata().getLastModified().toString()); IOUtils.copy(image.getObjectContent(), response.getOutputStream()); }catch (Exception e) { if(e instanceof AmazonS3Exception){ int statusCode = ((AmazonS3Exception) e).getStatusCode(); //System.out.println("Status Code : "+statusCode); response.setContentType("image/jpeg"); if(statusCode==HttpStatus.NOT_MODIFIED.value()){ response.setHeader("ETag",((AmazonS3Exception) e).getAdditionalDetails().get("ETag")); response.setHeader("Cache-Control",((AmazonS3Exception) e).getAdditionalDetails().get("Cache-Control")); response.setHeader("Last-Modified",((AmazonS3Exception) e).getAdditionalDetails().get("Last-Modified")); } response.setStatus(statusCode); } } }
This action works fine.
Now I want to publish a url to access the image of each profile. JSON format is something like this
{ "profileId" : 342308, "userId" : 342308, "firstname" : "Henry", "lastname" : "Seol", "title" : "Mr.", "largeImageUrl" : "https://<host>/image/<id>/<publicUrl>/<filename1.jpg>", "thumbImageUrl" : "https://<host>/image/<id>/<publicUrl>/<filename2.jpg>" }
I want to add this link instead of the value for "largeImageUrl" and "thumbImageUrl".
If I use the linkTo function in hate methods, it says that the corresponding method should not return void.
How to create such a dynamic link and add it to the resource?
source share