我尝试开发一个 api 来打开像 word 或 pdf 这样的文件。我用 swagger 这个 API 测试,但我有下面的错误。swagger 或前面给出的参数类似这样 -> Z:\Some\Path\To\My\File.docx。
我在探索者窗口上尝试了这个 pathFile,它工作正常。
堆栈跟踪
java.io.FileNotFoundException: InputStream resource [resource loaded through InputStream] cannot be resolved to absolute file path
at org.springframework.core.io.AbstractResource.getFile(AbstractResource.java:114) ~[spring-core-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at ... .DownloadDocumentResource.downloadFile(DownloadDocumentResource.java:28) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_92]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_92]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_92]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_92]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE]
Run Code Online (Sandbox Code Playgroud)
休息控制器
@RestController
public class DownloadDocumentResource {
@ResponseBody
@RequestMapping(method = RequestMethod.POST, path = {"/download"})
public ResponseEntity<InputStreamResource> downloadFile(@RequestBody String pathFile) throws IOException {
out.println(pathFile);
InputStreamResource resource = …Run Code Online (Sandbox Code Playgroud)