我有以下控制器方法,它将文件上传到我的服务器。我想为 Plupload 的状态返回 JSON。然而,响应似乎是作为分派而不是 json @ResponseBody 发回的。有任何想法吗?
private static final String RESP_SUCCESS = "{\"jsonrpc\" : \"2.0\", \"result\" : \"success\", \"id\" : \"id\"}";
private static final String RESP_ERROR = "{\"jsonrpc\" : \"2.0\", \"error\" : {\"code\": 101, \"message\": \"Failed to upload file.\"}, \"id\" : \"id\"}";
@RequestMapping(method = RequestMethod.POST)
public String uploadItem(@RequestBody MultipartFile file,
@RequestParam String name,
@RequestParam(required = false, defaultValue = "-1") int chunks,
@RequestParam(required = false, defaultValue = "-1") int chunk) {
Media media = new Media();
try {
Path path = Paths.get("/Users/username/Desktop/Test", file.getOriginalFilename());
media.setContentType(file.getContentType());
media.setFileName(file.getOriginalFilename());
media.setFileSize(file.getSize());
media.setFilePath(path.toString());
if (media.getContentType().contains("image")) {
Image image = new Image();
image.setImagePath(path.toString());
imageDao.save(image);
}
byte[] bytes = file.getBytes();
Files.write(path, bytes, StandardOpenOption.CREATE);
mediaDao.save(media);
return RESP_SUCCESS;
} catch (IOException e) {
e.printStackTrace();
}
return RESP_ERROR;
}
}
引发以下错误:
WARN - No mapping found for HTTP request with URI [/{"jsonrpc" : "2.0", "result" : "success", "id" : "id"}] in DispatcherServlet with name 'cr'