gpt4 book ai didi

java - MultipartFile 到 PDF 转换并下载此文件

转载 作者:行者123 更新时间:2023-12-02 03:28:25 25 4
gpt4 key购买 nike

friend 们,我的代码有一个问题

我想将 MultipartFile 转换为 pdf 并将其下载到特定位置,任何人都可以帮助我

@RequestMapping(value = "/uploadFile", method = RequestMethod.PUT, consumes = { "multipart/form-data" })
public Map<String, String> uploadFile(@RequestParam("uploadfile") MultipartFile pdfFile) throws Exception {

String url = pdfFile + "FileName";
File fileToSave = new File(url);
fileToSave.createNewFile();

FileOutputStream fos = new FileOutputStream(fileToSave);
fos.write(pdfFile.getBytes());
fos.close();

return null;
}

最佳答案

请尝试这个功能:

   public static File convert(MultipartFile file) throws IOException {
File convFile = new File(file.getOriginalFilename());
convFile.createNewFile();
FileOutputStream fos = new FileOutputStream(convFile);
fos.write(file.getBytes());
fos.close();
return convFile;
}

关于java - MultipartFile 到 PDF 转换并下载此文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56898580/

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