multipartFile转file修改文件名,再转回multipartFile

multipartFile转file修改文件名,再转回multipartFile,第1张

multipartFile转file修改文件名,再转回multipartFile
//临时文件地址
String[] filename = multipartFile.getOriginalFilename().split("\.");
String folderPath = System.getProperty("java.io.tmpdir") + File.separator + "ottc-ilp" + File.separator;
File folder = new File(folderPath);
folder.mkdirs();
String path = folderPath + File.separator + filename[0] + System.currentTimeMillis() + "." + filename[1];
File file = new File(path);
//转成file
FileUtils.copyInputStreamToFile(multipartFile.getInputStream(), file);
FileInputStream fileInputStream = new FileInputStream(file);
//转回multipartFile
MockMultipartFile file1 = new MockMultipartFile("file", file.getName(), null, fileInputStream);

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5563060.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存