springboot怎么多上传图片,然后让一个图片存两个地方
时间: 2023-04-10 12:05:12 浏览: 64
您可以使用Spring Boot的MultipartFile类来处理文件上传。您可以使用以下代码将文件保存到两个位置:
```
@PostMapping("/upload")
public String uploadFile(@RequestParam("file") MultipartFile file) {
try {
// Save file to first location
String firstLocation = "/path/to/first/location/" + file.getOriginalFilename();
Files.copy(file.getInputStream(), Paths.get(firstLocation), StandardCopyOption.REPLACE_EXISTING);
// Save file to second location
String secondLocation = "/path/to/second/location/" + file.getOriginalFilename();
Files.copy(file.getInputStream(), Paths.get(secondLocation), StandardCopyOption.REPLACE_EXISTING);
return "File uploaded successfully!";
} catch (IOException e) {
e.printStackTrace();
return "File upload failed!";
}
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)