预览上传代码提交
This commit is contained in:
parent
14ef69e98b
commit
ed53c81666
|
@ -1,6 +1,7 @@
|
||||||
package com.ruoyi.official.controller;
|
package com.ruoyi.official.controller;
|
||||||
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.domain.PageQuery;
|
import com.ruoyi.common.core.domain.PageQuery;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
@ -11,10 +12,16 @@ import com.ruoyi.official.domain.vo.CheckSysChunkVo;
|
||||||
import com.ruoyi.official.domain.vo.FileChunkFilelistVo;
|
import com.ruoyi.official.domain.vo.FileChunkFilelistVo;
|
||||||
import com.ruoyi.official.service.IFileChunkFilelistService;
|
import com.ruoyi.official.service.IFileChunkFilelistService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.core.io.InputStreamResource;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 已上传文件记录
|
* 已上传文件记录
|
||||||
|
@ -46,8 +53,14 @@ public class FileChunkFilelistController extends BaseController {
|
||||||
* @return 是否上传成功
|
* @return 是否上传成功
|
||||||
*/
|
*/
|
||||||
@PostMapping("/upload")
|
@PostMapping("/upload")
|
||||||
public R<Void> postFileUpload(@ModelAttribute FileChunkParamBo fileChunkParam, HttpServletResponse response) {
|
public R<Map<String,Object>> postFileUpload(@ModelAttribute FileChunkParamBo fileChunkParam, HttpServletResponse response) {
|
||||||
return toAjax(iFileChunkFilelistService.postFileUpload(fileChunkParam, response));
|
boolean flag = iFileChunkFilelistService.postFileUpload(fileChunkParam, response);
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
if (flag){
|
||||||
|
if (ObjectUtil.equal(fileChunkParam.getChunkNumber(),fileChunkParam.getTotalChunks()))map.put("needMerge", true);
|
||||||
|
return R.ok(map);
|
||||||
|
}
|
||||||
|
return R.warn("上传失败!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,4 +83,19 @@ public class FileChunkFilelistController extends BaseController {
|
||||||
return R.ok("操作成功", iFileChunkFilelistService.mergeFile(filelistBo));
|
return R.ok("操作成功", iFileChunkFilelistService.mergeFile(filelistBo));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件预览
|
||||||
|
* @param param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/showConver")
|
||||||
|
public void showImage(@RequestParam("url") String url, HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
try {
|
||||||
|
iFileChunkFilelistService.showFile(url,request,response);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,11 @@ public class GwIndex extends BaseEntity {
|
||||||
*/
|
*/
|
||||||
private String titleEnglish;
|
private String titleEnglish;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 视频链接地址
|
||||||
|
*/
|
||||||
|
private String videoLink;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 链接
|
* 链接
|
||||||
|
|
|
@ -40,6 +40,10 @@ public class GwIndexBo extends BaseEntity {
|
||||||
*/
|
*/
|
||||||
private String fileType;
|
private String fileType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 视频链接地址
|
||||||
|
*/
|
||||||
|
private String videoLink;
|
||||||
/**
|
/**
|
||||||
* 链接
|
* 链接
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -64,6 +64,11 @@ public class GwIndexVo {
|
||||||
*/
|
*/
|
||||||
private String twLink;
|
private String twLink;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 视频链接地址
|
||||||
|
*/
|
||||||
|
private String videoLink;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 图片标题英文描述
|
* 图片标题英文描述
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -8,8 +8,12 @@ import com.ruoyi.official.domain.vo.FileChunkFilelistVo;
|
||||||
import com.ruoyi.official.domain.bo.FileChunkFilelistBo;
|
import com.ruoyi.official.domain.bo.FileChunkFilelistBo;
|
||||||
import com.ruoyi.common.core.page.TableDataInfo;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
import com.ruoyi.common.core.domain.PageQuery;
|
import com.ruoyi.common.core.domain.PageQuery;
|
||||||
|
import org.springframework.core.io.InputStreamResource;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -57,4 +61,6 @@ public interface IFileChunkFilelistService {
|
||||||
CheckSysChunkVo getFileUpload(FileChunkParamBo fileChunkParam, HttpServletResponse response);
|
CheckSysChunkVo getFileUpload(FileChunkParamBo fileChunkParam, HttpServletResponse response);
|
||||||
|
|
||||||
String mergeFile(FileChunkFilelistBo FileChunkFilelistBo);
|
String mergeFile(FileChunkFilelistBo FileChunkFilelistBo);
|
||||||
|
|
||||||
|
void showFile(String imgUrl, HttpServletRequest request, HttpServletResponse response) throws IOException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,44 +1,45 @@
|
||||||
package com.ruoyi.official.service.impl;
|
package com.ruoyi.official.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
|
||||||
import com.ruoyi.common.core.page.TableDataInfo;
|
|
||||||
import com.ruoyi.common.core.domain.PageQuery;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.ruoyi.common.core.domain.PageQuery;
|
||||||
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import com.ruoyi.official.domain.FileChunkFilelist;
|
||||||
import com.ruoyi.official.domain.FileChunkParam;
|
import com.ruoyi.official.domain.FileChunkParam;
|
||||||
|
import com.ruoyi.official.domain.bo.FileChunkFilelistBo;
|
||||||
import com.ruoyi.official.domain.bo.FileChunkParamBo;
|
import com.ruoyi.official.domain.bo.FileChunkParamBo;
|
||||||
import com.ruoyi.official.domain.vo.CheckSysChunkVo;
|
import com.ruoyi.official.domain.vo.CheckSysChunkVo;
|
||||||
|
import com.ruoyi.official.domain.vo.FileChunkFilelistVo;
|
||||||
import com.ruoyi.official.domain.vo.FileChunkParamVo;
|
import com.ruoyi.official.domain.vo.FileChunkParamVo;
|
||||||
|
import com.ruoyi.official.mapper.FileChunkFilelistMapper;
|
||||||
import com.ruoyi.official.mapper.FileChunkParamMapper;
|
import com.ruoyi.official.mapper.FileChunkParamMapper;
|
||||||
|
import com.ruoyi.official.service.IFileChunkFilelistService;
|
||||||
import com.ruoyi.official.service.IFileChunkParamService;
|
import com.ruoyi.official.service.IFileChunkParamService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.ruoyi.official.domain.bo.FileChunkFilelistBo;
|
|
||||||
import com.ruoyi.official.domain.vo.FileChunkFilelistVo;
|
|
||||||
import com.ruoyi.official.domain.FileChunkFilelist;
|
|
||||||
import com.ruoyi.official.mapper.FileChunkFilelistMapper;
|
|
||||||
import com.ruoyi.official.service.IFileChunkFilelistService;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.Serializable;
|
import java.net.InetAddress;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.security.Security;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -243,6 +244,25 @@ public class FileChunkFilelistServiceImpl implements IFileChunkFilelistService {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showFile(String imgUrl, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||||
|
|
||||||
|
// 设置响应的类型为视频流
|
||||||
|
response.setContentType("video/mp4");
|
||||||
|
|
||||||
|
File videoFile = new File(filePath+imgUrl);
|
||||||
|
byte[] videoData = Files.readAllBytes(videoFile.toPath());
|
||||||
|
|
||||||
|
// 设置响应的长度为视频文件的长度
|
||||||
|
response.setContentLength(videoData.length);
|
||||||
|
|
||||||
|
OutputStream outputStream = response.getOutputStream();
|
||||||
|
// 将视频数据写入输出流
|
||||||
|
outputStream.write(videoData);
|
||||||
|
outputStream.flush();
|
||||||
|
outputStream.close();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成块文件所在地址
|
* 生成块文件所在地址
|
||||||
*/
|
*/
|
||||||
|
@ -308,7 +328,6 @@ public class FileChunkFilelistServiceImpl implements IFileChunkFilelistService {
|
||||||
Files.delete(path);
|
Files.delete(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("合并出现错误:" + e);
|
log.error("合并出现错误:" + e);
|
||||||
throw new RuntimeException("合并出现错误," + e.getMessage());
|
throw new RuntimeException("合并出现错误," + e.getMessage());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user