用java spring boot 代码写一个接口,批量上传docx到Linux 指定目录
时间: 2023-06-08 21:06:36 浏览: 76
好的,以下是使用Java Spring Boot编写的批量上传docx到Linux的指定目录的接口:
```
@RestController
public class FileUploadController {
private static final String UPLOAD_DIR = "/path/to/upload/directory"; // 指定上传目录
@PostMapping("/upload")
public ResponseEntity<Object> uploadFiles(@RequestParam("files") MultipartFile[] files) {
for (MultipartFile file : files) {
try {
Path path = Paths.get(UPLOAD_DIR, file.getOriginalFilename());
Files.copy(file.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("文件上传失败");
}
}
return ResponseEntity.ok("文件上传成功");
}
}
```
您可以通过发送一个POST请求到`/upload`接口,将docx文件作为`files`参数一次性批量上传到指定的Linux目录中。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.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)