1

I have a controller method that creates some files on the server and returns their path.:

@RequestMapping(value="/file", method=RequestMethod.GET)
    public @ResponseBody String retrieveFile(@RequestParam("userid") String userId){
//Do some work, save a file
File newFile=Utils.getFile(userId);
FileSystemResource f=new FileSystemResource(newFile);
                return f.getURL().toString();
}

When running this on my local machine, the response is like this:

file:/D:/SDKs/spring-tool-suite-3.7.1.RELEASE-e4.5.1-win32-x86_64/sts-bundle/sts-3.7.1.RELEASE/file.jpg

when I deployed the app to aws beanstalk, the response was like this:

file:/usr/share/tomcat8/file.jpg

How can I retrieve the absolute file path in a fashion similar to what happens on the local machine?

Mina Wissa
  • 10,923
  • 13
  • 90
  • 158
  • 1
    That *is* an absolute path (it starts at /, the filesystem root). Can you explain your question in more detail? – Thorn G Nov 16 '15 at 14:17
  • 1
    @TomG thanks, I want to retrieve a url to the location of the file, so that a client application download it – Mina Wissa Nov 16 '15 at 14:24

1 Answers1

1

Although depending on the server you may not have the same path as on a local machine...

As long as you tried the normal,

file.getAbsolutePath()

function in http://docs.oracle.com/javase/7/docs/api/java/io/File.html and it returned the same there is no way to get the drive name and everything especially if its a VPS

Ya Wang
  • 1,758
  • 1
  • 19
  • 41
  • 1
    Thanks, is there a way to get the file's real path so that it can be downloaded by clients? – Mina Wissa Nov 16 '15 at 13:46
  • http://stackoverflow.com/questions/10991089/how-to-download-file-from-url-using-spring-mvc it seems like you can normally send a stream with data through httpresponse out to client if you want you can also do something like http://stackoverflow.com/questions/5673260/downloading-a-file-from-spring-controllers – Ya Wang Nov 16 '15 at 13:50