实战之oss附件批量下载,借鉴网上一些案例,但是没有达到预期效果,结合项目需求。实现远程将oss上的文件进行压缩,并提供给前端用户下载,经过测试完美实现该功能。
@PostMapping("downLoadZip")
public void downLoadZip(@RequestBody CourseDetailVo detailVo,
HttpServletResponse response,
@RequestParam(value = "customFileName", required = false, defaultValue = "default.zip") String customFileName) throws IOException {
List<AttachZipDto> objectNames = detailVo.getZipDtoList();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try (ZipOutputStream zipOut = new ZipOutputStream(byteArrayOutputStream)) {
for (AttachZipDto objectName : objectNames) {
String fileUrl = objectName.getFileOssUr();
String extension = TouUtil.getFileExtension(objectName.getFileOssUr());
if (fileUrl.startsWith("/")) {
fileUrl = fileUrl.substring(1);
}

最低0.47元/天 解锁文章
1681

被折叠的 条评论
为什么被折叠?



