Scala 停止文件路径上的双重编码的方法是什么?
我想使用UrlResource获取资源对象中的文件,但是.toUri方法对路径进行编码,这样就存在文件,但仍然无法获取 我的代码是:Scala 停止文件路径上的双重编码的方法是什么?,scala,path,resources,filestream,Scala,Path,Resources,Filestream,我想使用UrlResource获取资源对象中的文件,但是.toUri方法对路径进行编码,这样就存在文件,但仍然无法获取 我的代码是: val filepath = Paths.get(getClass.getClassLoader.getResource("some file4216.pdf").getPath) val resource : Resource = new UrlResource(filepath.toUri) val contentType = "application/p
val filepath = Paths.get(getClass.getClassLoader.getResource("some file4216.pdf").getPath)
val resource : Resource = new UrlResource(filepath.toUri)
val contentType = "application/pdf"
ResponseEntity.ok()
.contentType(MediaType.parseMediaType(contentType))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename + "\"")
.body(resource)
它将空间编码为“%20”,但也会执行编码并将“%”转换为“%2520”。
这就是为什么找不到文件的原因
给出以下路径:
/home/user/Live_Projects/some-project/some-project-api/build/resources/main/some%2520file4216.pdf
我只想要
%20
而不是%2520
你使用什么web框架?我想知道响应性来自哪里。ThanksResponseEntity从控制器方法传递。如下所示@GetMapping(数组(“/downloadFile”))def downloadFile(@RequestParam downloadFilePath:String,response:HttpServletResponse):ResponseEntity[String]={log.info(“内部downloadFile”)fileService.downloadFile(downloadFilePath,response)}