Announcement Announcement Module
Collapse
No announcement yet.
Get Path Variable with out annotation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Get Path Variable with out annotation

    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
    Code:
    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
    my Controller to satisfy the option one url is

    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;
    	}
    
    }
    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.

    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
    Last edited by kannanMugundan; Jan 25th, 2012, 03:10 AM.
Working...
X