怎么用ps做网站超链接银川网站建设公司哪家好
怎么用ps做网站超链接,银川网站建设公司哪家好,wordpress图片网盘插件腾讯,网站改版后不收录我的需求是一个可以批量下载文件或文件夹的接口#xff0c;下载一个文件就正常下载#xff0c;下载多个文件或单个多个文件夹都压缩成zip下载 本来想的是直接用hutool里面的ziputil工具类就行#xff0c;但是我这里报错的文件都是用随机字符串命名的#xff0c;直接用ZipUt…我的需求是一个可以批量下载文件或文件夹的接口下载一个文件就正常下载下载多个文件或单个多个文件夹都压缩成zip下载 本来想的是直接用hutool里面的ziputil工具类就行但是我这里报错的文件都是用随机字符串命名的直接用ZipUtil.zip方法下载下来的压缩包中文件都是原本文件的随机字符串名称
下面是我的处理方式其中的一些工具类和压缩相关的类还是用的hutool中的只不过没有用ZipUtil封装好的方法
OverrideOperLog(type OperType.DOWNLOAD)public void download(ListString ids) {ListWebDisk webDiskList this.webDiskMapper.selectList(new QueryWrapperWebDisk().in(id, ids));if (webDiskList.isEmpty()) {throw new RuntimeException(文件不存在下载失败);}if (webDiskList.size() 1 webDiskList.get(0).isFile()) {WebDisk webDisk webDiskList.get(0);try (FileInputStream is new FileInputStream(this.getFullPath(webDisk));ServletOutputStream os response.getOutputStream()) {response.setContentType(request.getSession().getServletContext().getMimeType(webDisk.getFileSuffix())); // 获取文件的mimetyperesponse.setHeader(content-disposition, attachment;fileName URLEncoder.encode(webDisk.getOriginName(), UTF-8));IoUtil.copy(is, os);} catch (IOException e) {e.printStackTrace();throw new RuntimeException(下载失败系统内部错误);}} else {response.setContentType(request.getSession().getServletContext().getMimeType(zip)); // 获取文件的mimetypetry (ZipOutputStream zos new ZipOutputStream(response.getOutputStream())) {response.setHeader(content-disposition, attachment;fileName URLEncoder.encode(FileNameUtil.mainName(webDiskList.get(0).getOriginName()) .zip, UTF-8));webDiskList.forEach(webDisk - {try {this.addFileToZip(webDisk, zos, , new HashMap());} catch (IOException e) {e.printStackTrace();throw new RuntimeException(e);}});} catch (IOException e) {throw new RuntimeException(e);}}}
主要的方法就是下面这个 addFileToZip方法
因为上传文件的时候用随机字符串命名就是为了防止文件名称重复所以这里打压缩包的时候给他们都设置为上传时候的原名称但是为了防止名称重复以名称后面累加括号加数字的方式重命名了
因为我上传的时候校验了不能上传重复名称的文件夹所以我这里就只处理了重名的文件 private void addFileToZip(WebDisk webDisk, ZipOutputStream zos, String path, MapString, Integer nameCount) throws IOException {String filePath this.getFullPath(webDisk);File file FileUtil.file(filePath);String curFilePath path (webDisk.isFile() ? webDisk.getOriginName() : (webDisk.getOriginName() /));ZipEntry zipEntry new ZipEntry(curFilePath);try {zos.putNextEntry(zipEntry);} catch (ZipException e) {// 有重复名称文件String mainName FileNameUtil.mainName(curFilePath);String extName FileNameUtil.extName(curFilePath);int num MapUtil.getInt(nameCount, curFilePath, 0) 1;String newFilePath path mainName ( num ) . extName;zipEntry new ZipEntry(newFilePath);zos.putNextEntry(zipEntry);nameCount.put(curFilePath, num);}if (file.isFile()) {try (FileInputStream is new FileInputStream(file)) {IoUtil.copy(is, zos);} catch (IOException e) {e.printStackTrace();}} else if (file.isDirectory()) {this.webDiskMapper.selectList(new QueryWrapperWebDisk().eq(pid, webDisk.getId()).eq(is_delete, 0)).forEach(sub - {try {this.addFileToZip(sub, zos, webDisk.getOriginName() File.separator, nameCount);} catch (IOException e) {e.printStackTrace();}});}zos.closeEntry();}
需要注意的是我这里目录的层级关系已经维护到表里了所以递归找下级的时候直接查的库
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/90137.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!