我有在服務器上創建一些文件,返回其路徑:Spring Controller:返回文件路徑的方法?
@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();
}
當我的本地機器上運行這個控制器的方法,反應是這樣的:
文件:/ d:/SDKs/spring-tool-suite-3.7.1.RELEASE-e4.5.1-win32-x86_64/sts-bundle/sts-3.7.1.RELEASE/file.jpg
當我部署應用程序aws beanstalk,響應是這樣的:
文件:/usr/share/tomcat8/file.jpg
我怎麼能在類似於本地機器上會發生什麼方式獲取絕對文件路徑?
這是* *的AB溶質路徑(它始於/,文件系統根目錄)。你能否更詳細地解釋你的問題? –
@TomG謝謝,我想檢索一個URL到文件的位置,以便客戶端應用程序下載它 –