作者:0704034铜豌豆 | 来源:互联网 | 2023-10-13 13:52
代码:try{URLvideoImagePathUrlnewURL(file:videoImagePath);一定要加file:FilefnewFile(vid
代码:
try {
URL videoImagePathUrl = new URL("file:///"+videoImagePath); //一定要加 file:///
File f=new File(videoImagePathUrl.toURI());
FileItem fileItem = new DiskFileItem("mainFile", Files.probeContentType(f.toPath()), false, f.getName(), (int) f.length(), f.getParentFile());
try (InputStream input = new FileInputStream(f); OutputStream os = fileItem.getOutputStream();) {
IOUtils.copy(input, os);
MultipartFile mulFile = new CommonsMultipartFile(fileItem);
ProductImage productImage = productImageService.generate(mulFile);
productImage.setOrder(0);
JSONObject jsOnObject=new JSONObject();
jsonObject.append("source", productImage.getSource());
jsonObject.append("large", productImage.getLarge());
jsonObject.append("medium", productImage.getMedium());
jsonObject.append("thumbnail", productImage.getThumbnail());
jsonObject.append("order",productImage.getOrder());
videoImageUrl=jsonObject.toString();
System.out.println(productImage.toString());
}
}catch (MalformedURLException e) {
e.printStackTrace();
}