gpt4 book ai didi

java - 无法解析 URI 的方法 'resolve'

转载 作者:行者123 更新时间:2023-11-30 02:07:58 25 4
gpt4 key购买 nike

我正在制作一个 Spring Boot 应用程序来提供图像。我的 createFile 方法尝试从 POST 请求获取 URI,但无法解析文件名。

在下面,我尝试发出 POST 请求来提供图像。我在 URI 下的 resolve 方法上遇到错误。我尝试了 3 次导入,如下所示:

//1
import java.net.URI;
//2
import com.sun.org.apache.xml.internal.utils.URI;
//3
import com.sun.org.apache.xerces.internal.util.URI;

这些似乎都不起作用。

下面是我尝试发出的用于提供图像的 POST 请求。

private static final String BASE_PATH = "/images";
//for Curl. Development and testing
@RequestMapping(method = RequestMethod.POST,value = BASE_PATH )
@ResponseBody
public ResponseEntity<?> createFile(@RequestParam("file") MultipartFile file, HttpServletRequest servletRequest) {

try {
imageService.createImage(file);
final URI locationUri = new Uri(servletRequest.getRequestURL().toString() + "/")
.resolve(file.getOriginalFilename() + "/raw");//error here on resolve
return ResponseEntity.created(locationUri)
.body("Succesfull" + file.getOriginalFilename());


} catch (IOException e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body("Could not find " + file.getOriginalFilename() + "=>" + e.getMessage());

}
}

最佳答案

您好,请将 Uri 更改为如下所示的 URI

final URI locationUri = new URI(servletRequest.getRequestURL().toString() + "/")
.resolve(file.getOriginalFilename() + "/raw");

关于java - 无法解析 URI 的方法 'resolve',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50961172/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com