分片上传修改
This commit is contained in:
parent
4b8e15abae
commit
7c07f7dfd0
|
@ -98,40 +98,52 @@ public class SysOssController extends BaseController {
|
|||
*/
|
||||
@Log(title = "本地文件上传", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/addPartsUpload")
|
||||
public R<Map<String, String>> addPartsUpload(@RequestPart("file") MultipartFile file, HttpServletRequest req) {
|
||||
Map<String,String> map=new HashMap<>();
|
||||
String realPath = req.getSession().getServletContext().getRealPath("/uploadFile/");
|
||||
String format = sdf.format(new Date());
|
||||
///www/wwwroot/guanwang/web/image/file/upload/
|
||||
// String filePath=uploadPath+"/file/upload/";
|
||||
File folder = new File(realPath + format);
|
||||
if (!folder.isDirectory()){
|
||||
folder.mkdirs();
|
||||
}
|
||||
String oldName = file.getOriginalFilename();
|
||||
String newName = UUID.randomUUID().toString() + oldName.substring(oldName.lastIndexOf("."), oldName.length());
|
||||
public R<Map<String, String>> addPartsUpload(@RequestPart("file") MultipartFile file) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
|
||||
String filePath = uploadPath + "/file/upload/";
|
||||
try {
|
||||
file.transferTo(new File(realPath,newName));
|
||||
String filePath = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort() + "/uploadFile" + format + newName;
|
||||
Long image = iSysImageService.uploadImage(newName,filePath);
|
||||
map.put("url",filePath);
|
||||
map.put("fileName",newName);
|
||||
map.put("ossId",image.toString());
|
||||
if (file.isEmpty()) {
|
||||
return R.warn("文件为空");
|
||||
}
|
||||
|
||||
String fileName = System.currentTimeMillis() + "-" + file.getOriginalFilename();
|
||||
//文件上传的路径(当前项目的根目录)
|
||||
|
||||
System.err.println(filePath);
|
||||
// 创建目标目录(如果不存在)
|
||||
File directory = new File(filePath);
|
||||
if (!directory.exists()) {
|
||||
directory.mkdirs();
|
||||
}
|
||||
// 保存文件到目标目录
|
||||
File uploadFile = new File(directory.getAbsolutePath() + File.separator + fileName);
|
||||
file.transferTo(uploadFile);
|
||||
//上传服务器地址
|
||||
String pathFan = filePath.replace("\\", "/");
|
||||
//filePath获取到的地址斜杠是“ \ ”的(单斜杠是特殊符号,得用双斜杠代替),得换成“ / ”才能访问到
|
||||
//返回全路径图片地址
|
||||
String returnPath = ("http://47.121.27.78:8008/upload/" + fileName).replace("\\", "/");
|
||||
//修改数据库
|
||||
Long image = iSysImageService.uploadImage(fileName, returnPath);
|
||||
System.err.println("替换后:" + pathFan);
|
||||
map.put("url", returnPath);
|
||||
map.put("fileName", fileName);
|
||||
map.put("ossId", image.toString());
|
||||
return R.ok(map);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
return R.warn("文件上传失败: " + e);
|
||||
}
|
||||
return R.warn("文件上传失败!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 下载OSS对象
|
||||
*
|
||||
* @param ossId OSS对象ID
|
||||
*/
|
||||
/**
|
||||
* 下载OSS对象
|
||||
*
|
||||
* @param ossId OSS对象ID
|
||||
*/
|
||||
@SaCheckPermission("system:oss:download")
|
||||
@GetMapping("/download/{ossId}")
|
||||
public void download(@PathVariable Long ossId, HttpServletResponse response) throws IOException {
|
||||
|
|
|
@ -49,6 +49,12 @@ public class GwIndex extends BaseEntity {
|
|||
*/
|
||||
private String titleEnglish;
|
||||
|
||||
|
||||
/**
|
||||
* 链接
|
||||
*/
|
||||
private String twLink;
|
||||
|
||||
/**
|
||||
* 业务名称英文描述
|
||||
*/
|
||||
|
|
|
@ -60,13 +60,11 @@ public class FileChunkFilelistBo extends BaseEntity {
|
|||
/**
|
||||
* 创建者id
|
||||
*/
|
||||
@NotNull(message = "创建者id不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private Long createUserId;
|
||||
|
||||
/**
|
||||
* 更新者id
|
||||
*/
|
||||
@NotNull(message = "更新者id不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private Long updateUserId;
|
||||
|
||||
|
||||
|
|
|
@ -40,6 +40,11 @@ public class GwIndexBo extends BaseEntity {
|
|||
*/
|
||||
private String fileType;
|
||||
|
||||
/**
|
||||
* 链接
|
||||
*/
|
||||
private String twLink;
|
||||
|
||||
/**
|
||||
* 业务类型 0:石油化工业务 1:基建业务 2:铁矿石业务 3:燃气业务
|
||||
*/
|
||||
|
|
|
@ -59,6 +59,11 @@ public class GwIndexVo {
|
|||
@ExcelProperty(value = "业务名称")
|
||||
private String businessName;
|
||||
|
||||
/**
|
||||
* 链接
|
||||
*/
|
||||
private String twLink;
|
||||
|
||||
/**
|
||||
* 图片标题英文描述
|
||||
*/
|
||||
|
|
|
@ -310,7 +310,7 @@ public class FileChunkFilelistServiceImpl implements IFileChunkFilelistService {
|
|||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
log.error("合并出现错误:" + e.getMessage(), e);
|
||||
log.error("合并出现错误:" + e);
|
||||
throw new RuntimeException("合并出现错误," + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user