Hi,
I need a spring controller to return images/file by reading it from Disk.
I think there is 2 ways to make a call from client
options
my Controller to satisfy the option one url isCode:http://localhost/ams/spring/files/images/get?directory=WORKSHOP_INFRA&fileName=45_slogan.jpg http://localhost/ams/spring/files/images/get/WORKSHOP_INFRA/45_slogan.jpg
when I dynamically create the first URL in flex client and use it to render images, is not working, due to & special Char, and geting IP address etc etc.Code:public class FilesController extends MultiActionController { public ModelAndView getFile(HttpServletRequest request,HttpServletResponse response) throws Exception { String fileName = ServletRequestUtils.getRequiredStringParameter(request, "fileName"); String directory = ServletRequestUtils.getRequiredStringParameter(request, "directory"); //My method to read file from disk and return the bytes byte[] fileBytes =getFileInBytes(directory,fileName) response.setContentType(fileName.substring(fileName.lastIndexOf(".") + 1)); response.setContentLength(fileBytes.length); response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); FileCopyUtils.copy(fileBytes, response.getOutputStream()); return null; } }
So thought to use the 2nd URL pattern, but all examples, I found are using annotation path variable etc.
I am yet to learn annotations. so to get the file name and directory from the URL, I need to manually parse the URL using substring, last index etc. Is there any utility in Spring to get me the path varaiable, with out annotation.
Thanks


Reply With Quote
