|
@@ -18,8 +18,8 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.*;
|
|
|
import java.util.List;
|
|
|
import java.util.UUID;
|
|
|
|
|
@@ -99,7 +99,7 @@ public class ProjectFileServiceImpl extends ServiceImpl<ProjectFileMapper, Proje
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg dowloadFile(ProjectFile projectFile, String token) {
|
|
|
+ public HttpRespMsg dowloadFile(ProjectFile projectFile, String token,String downLoadpath,HttpServletResponse response) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
User user = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", token));
|
|
|
//添加上传记录
|
|
@@ -113,6 +113,32 @@ public class ProjectFileServiceImpl extends ServiceImpl<ProjectFileMapper, Proje
|
|
|
projectOperationDynamicsMapper.insert(dynamics);
|
|
|
return msg;
|
|
|
}
|
|
|
+ public void downloadLocal(HttpServletResponse response, String downLoadpath,ProjectFile file) throws FileNotFoundException {
|
|
|
+ // 下载本地文件
|
|
|
+ String fileName = file.getFileName().toString(); // 文件的默认保存名
|
|
|
+ // 读到流中
|
|
|
+ File dir = null;
|
|
|
+ dir = new File(downLoadpath);
|
|
|
+ // D://cloud/upload 文件上传后所存储的位置,部署到服务器上时配置服务器地址即可
|
|
|
+ if (!dir.exists()) {
|
|
|
+ dir.mkdirs();
|
|
|
+ }
|
|
|
+ InputStream inStream = new FileInputStream(downLoadpath);// 文件的存放路径
|
|
|
+ // 设置输出的格式
|
|
|
+ response.reset();
|
|
|
+ response.setContentType("bin");
|
|
|
+ response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
|
|
|
+ // 循环取出流中的数据
|
|
|
+ byte[] b = new byte[100];
|
|
|
+ int len;
|
|
|
+ try {
|
|
|
+ while ((len = inStream.read(b)) > 0)
|
|
|
+ response.getOutputStream().write(b, 0, len);
|
|
|
+ inStream.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public HttpRespMsg getFileList(UserVO userVO) {
|