Java 无法解析方法';解决';对于URI
我正在制作一个springboot应用程序来提供图像服务。我的Java 无法解析方法';解决';对于URI,java,spring,uri,Java,Spring,Uri,我正在制作一个springboot应用程序来提供图像服务。我的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.interna
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;
这些似乎都不起作用
下面是我试图为图片服务的帖子请求
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());
}
}
private static final String BASE_PATH=“/images”;
//为了卷曲。开发和测试
@RequestMapping(method=RequestMethod.POST,value=BASE\u路径)
@应答器
公共响应属性createFile(@RequestParam(“文件”)多部分文件文件,HttpServletRequest servletRequest){
试一试{
createImage(文件);
最终URI位置URI=新URI(servletRequest.getRequestURL().toString()+“/”)
.resolve(file.getOriginalFilename()+“/raw”);//解析时出现错误
return ResponseEntity.created(locationUri)
.body(“成功”+文件.getOriginalFilename());
}捕获(IOE异常){
返回ResponseEntity.status(HttpStatus.INTERNAL\u SERVER\u错误)
.body(“找不到”+file.getOriginalFilename()+“=>”+e.getMessage());
}
}
您好,请将Uri更改为Uri,如下所示
final URI locationUri = new URI(servletRequest.getRequestURL().toString() + "/")
.resolve(file.getOriginalFilename() + "/raw");