分片上传修改
This commit is contained in:
parent
4b8e15abae
commit
7c07f7dfd0
|
@ -98,40 +98,52 @@ public class SysOssController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@Log(title = "本地文件上传", businessType = BusinessType.INSERT)
|
@Log(title = "本地文件上传", businessType = BusinessType.INSERT)
|
||||||
@PostMapping("/addPartsUpload")
|
@PostMapping("/addPartsUpload")
|
||||||
public R<Map<String, String>> addPartsUpload(@RequestPart("file") MultipartFile file, HttpServletRequest req) {
|
public R<Map<String, String>> addPartsUpload(@RequestPart("file") MultipartFile file) {
|
||||||
Map<String,String> map=new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
String realPath = req.getSession().getServletContext().getRealPath("/uploadFile/");
|
|
||||||
String format = sdf.format(new Date());
|
String filePath = uploadPath + "/file/upload/";
|
||||||
///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());
|
|
||||||
try {
|
try {
|
||||||
file.transferTo(new File(realPath,newName));
|
if (file.isEmpty()) {
|
||||||
String filePath = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort() + "/uploadFile" + format + newName;
|
return R.warn("文件为空");
|
||||||
Long image = iSysImageService.uploadImage(newName,filePath);
|
}
|
||||||
map.put("url",filePath);
|
|
||||||
map.put("fileName",newName);
|
String fileName = System.currentTimeMillis() + "-" + file.getOriginalFilename();
|
||||||
map.put("ossId",image.toString());
|
//文件上传的路径(当前项目的根目录)
|
||||||
|
|
||||||
|
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);
|
return R.ok(map);
|
||||||
} catch (IOException ex) {
|
} catch (IOException e) {
|
||||||
ex.printStackTrace();
|
return R.warn("文件上传失败: " + e);
|
||||||
}
|
}
|
||||||
return R.warn("文件上传失败!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载OSS对象
|
* 下载OSS对象
|
||||||
*
|
*
|
||||||
* @param ossId OSS对象ID
|
* @param ossId OSS对象ID
|
||||||
*/
|
*/
|
||||||
@SaCheckPermission("system:oss:download")
|
@SaCheckPermission("system:oss:download")
|
||||||
@GetMapping("/download/{ossId}")
|
@GetMapping("/download/{ossId}")
|
||||||
public void download(@PathVariable Long ossId, HttpServletResponse response) throws IOException {
|
public void download(@PathVariable Long ossId, HttpServletResponse response) throws IOException {
|
||||||
|
|
|
@ -49,6 +49,12 @@ public class GwIndex extends BaseEntity {
|
||||||
*/
|
*/
|
||||||
private String titleEnglish;
|
private String titleEnglish;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 链接
|
||||||
|
*/
|
||||||
|
private String twLink;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 业务名称英文描述
|
* 业务名称英文描述
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -60,13 +60,11 @@ public class FileChunkFilelistBo extends BaseEntity {
|
||||||
/**
|
/**
|
||||||
* 创建者id
|
* 创建者id
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "创建者id不能为空", groups = { AddGroup.class, EditGroup.class })
|
|
||||||
private Long createUserId;
|
private Long createUserId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新者id
|
* 更新者id
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "更新者id不能为空", groups = { AddGroup.class, EditGroup.class })
|
|
||||||
private Long updateUserId;
|
private Long updateUserId;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,11 @@ public class GwIndexBo extends BaseEntity {
|
||||||
*/
|
*/
|
||||||
private String fileType;
|
private String fileType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 链接
|
||||||
|
*/
|
||||||
|
private String twLink;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 业务类型 0:石油化工业务 1:基建业务 2:铁矿石业务 3:燃气业务
|
* 业务类型 0:石油化工业务 1:基建业务 2:铁矿石业务 3:燃气业务
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -59,6 +59,11 @@ public class GwIndexVo {
|
||||||
@ExcelProperty(value = "业务名称")
|
@ExcelProperty(value = "业务名称")
|
||||||
private String businessName;
|
private String businessName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 链接
|
||||||
|
*/
|
||||||
|
private String twLink;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 图片标题英文描述
|
* 图片标题英文描述
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -310,7 +310,7 @@ public class FileChunkFilelistServiceImpl implements IFileChunkFilelistService {
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("合并出现错误:" + e.getMessage(), e);
|
log.error("合并出现错误:" + e);
|
||||||
throw new RuntimeException("合并出现错误," + e.getMessage());
|
throw new RuntimeException("合并出现错误," + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user