|
@@ -41,6 +41,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
@@ -252,24 +253,17 @@ public class SceneUploadServiceImpl extends ServiceImpl<ISceneUploadMapper, Scen
|
|
File outFile = new File(descFilePath);
|
|
File outFile = new File(descFilePath);
|
|
//定义处理流
|
|
//定义处理流
|
|
try(
|
|
try(
|
|
- InputStream inputStream = new BufferedInputStream(new FileInputStream(outFile));
|
|
|
|
- OutputStream outputStream = new BufferedOutputStream(response.getOutputStream())
|
|
|
|
|
|
+ FileInputStream inputStream = new FileInputStream(outFile);
|
|
|
|
+ OutputStream outputStream = response.getOutputStream()
|
|
){
|
|
){
|
|
- response.reset();
|
|
|
|
- // 设置在下载框默认显示的文件名
|
|
|
|
- response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(file.getOriginalFilename(), "UTF-8"));
|
|
|
|
- //写明文件大小
|
|
|
|
- response.addHeader("Content-Length", "" + outFile.length());
|
|
|
|
- // 指明response的返回对象是文件流
|
|
|
|
- response.setContentType("application/octet-stream");
|
|
|
|
- log.debug("开始读取文件流");
|
|
|
|
- //返回从该输入流中可以读取(或跳过)的字节数的估计值,而不会被下一次调用此输入流的方法阻塞
|
|
|
|
- byte[] bytes = new byte[inputStream.available()];
|
|
|
|
- //将pdf的内容写入bytes中
|
|
|
|
- inputStream.read(bytes);
|
|
|
|
- //将bytes中的内容写入
|
|
|
|
- outputStream.write(bytes);
|
|
|
|
- //刷新输出流,否则不会写出数据
|
|
|
|
|
|
+ byte[] cache = new byte[1024];
|
|
|
|
+ response.setHeader(HttpHeaders.CONTENT_TYPE, "video/mp4");
|
|
|
|
+ response.setHeader(HttpHeaders.CONTENT_LENGTH, inputStream.available()+"");
|
|
|
|
+ response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode(file.getOriginalFilename(), "UTF-8"));
|
|
|
|
+ int flag;
|
|
|
|
+ while ((flag = inputStream.read(cache)) != -1) {
|
|
|
|
+ outputStream.write(cache, 0, flag);
|
|
|
|
+ }
|
|
outputStream.flush();
|
|
outputStream.flush();
|
|
}finally {
|
|
}finally {
|
|
// FileUtil.delFile(oldFile.getPath());
|
|
// FileUtil.delFile(oldFile.getPath());
|