gpt4 book ai didi

java - RestTemplate 调用,其中函数的参数是 MultipartHttpServletRequest 请求

转载 作者:行者123 更新时间:2023-12-01 16:22:39 25 4
gpt4 key购买 nike

您好,我必须进行 Resttemplate 调用才能对以下函数进行调用,其中参数是 MultiPartHttpServletRequest 请求、HttpServletRequest requestForm、HttpServletResponse 响应

Map<String, String> upload(MultipartHttpServletRequest request,
HttpServletRequest requestForm, HttpServletResponse response, @RequestParam("name") String name,
@RequestParam("id") String id,
@RequestParam(value = "contanctno", required = false, defaultValue = Constants.DIGITS) String contactNo,
@RequestParam(value = "address", required = false,) String address) throws InvalidReqException

除此之外,问题是我有要发送的文件,但如何发送该特定文件以及名称 version.pdf,其中版本总是变化。有人可以帮助我吗

请求方法=POST

最佳答案

假设您要将新文件以新名称保存在硬盘上,您可以添加 MultipartFile 作为参数,并将文件内容从上传的文件复制到硬盘上的新文件中。磁盘:

Map<String, String> upload(MultipartHttpServletRequest request,
HttpServletRequest requestForm, HttpServletResponse response, @RequestParam("name") String name,
@RequestParam("id") String id,
@RequestParam(value = "contanctno", required = false, defaultValue = Constants.DIGITS) String contactNo,
@RequestParam(value = "address", required = false) String address,
@RequestParam("file") MultipartFile file) throws InvalidReqException {

String newFileName = "newFileName.pdf";
File newPdf = new File(newFileName);
Files.copy(file.getInputStream(), newPdf.toPath());

// more code...
}

关于java - RestTemplate 调用,其中函数的参数是 MultipartHttpServletRequest 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62230725/

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