Commit b0adf821 authored by m1991's avatar m1991

后台接口——用户与资讯后台接口

parent 7b898ff7
......@@ -180,78 +180,82 @@ public class UploadServiceImpl implements UploadService {
//过滤传入的邀请码带有“”的符号
inviteCode = inviteCode.replace("\"", "").replace("\"", "");
//获取上传图片数量,打印在控制台
System.out.println("上传图片数量" + files.length);
//创建集合
List<Map<String, Object>> root = new ArrayList<Map<String, Object>>();
String fileName1 = null;
Long time = System.currentTimeMillis();
Map<String, Object> result = new HashMap<String, Object>();//一个文件上传的结果
String msg = "";//上传结果信息
//上传图片不为空时
long sa = 0;
for (MultipartFile file : files) {
sa = file.getSize();
}
if (sa > 0) {
//遍历图片数据
if(null!=files&&"".equals(files)){
System.out.println("上传图片数量" + files.length);
//创建集合
List<Map<String, Object>> root = new ArrayList<Map<String, Object>>();
String fileName1 = null;
Long time = System.currentTimeMillis();
Map<String, Object> result = new HashMap<String, Object>();//一个文件上传的结果
String msg = "";//上传结果信息
//上传图片不为空时
long sa = 0;
for (MultipartFile file : files) {
//判断上传文件格式
String fileType = file.getContentType();
log.info(file.getSize() + "");
if (("image/jpeg").equals(fileType) || ("image/png").equals(fileType) || ("image/gif").equals(fileType) || ("image/jpg").equals(fileType) || ("image/bmp").equals(fileType) || ("application/octet-stream").equals(fileType)) {
//上传后保存的文件名(需要防止图片重名导致的文件覆盖)
//获取文件名
fileName1 = file.getOriginalFilename();
String fileName;
//获取文件后缀名
try {
String suffixName = fileName1.substring(fileName1.lastIndexOf("."));
//重新生成文件名
fileName = "1" + UUID.randomUUID() + suffixName;//文件新名称
} catch (
Exception e
) {
//重新生成文件名
fileName = "1" + UUID.randomUUID() + fileName1 + ".jpg";//文件新名称
}
//设置文件存储路径,可以存放在你想要指定的路径里面
String Path = "/upload/";
String Path1 = "/opt/upload/video/"; //上传图片存放位置
zxUrl += Path + fileName + ",";
String UrlzxPath ="/opt/upload/video/";
xxurl=UrlzxPath+ fileName;
if (FileUtils.upload(file, Path1, fileName)) {
//文件存放的相对路径(一般存放在数据库用于img标签的src)
String relativePath = "用于判断是否图片上传成功,返回值有:" + fileName;
result.put("relativePath", relativePath);//前端根据是否存在该字段来判断上传是否成功
msg = "图片上传成功";
result.put("zxUrl", zxUrl);
FileOutputStream fouts = null;
Img.from(cn.hutool.core.io.FileUtil.file(xxurl))
.setQuality(0.8)//压缩比率
.write(cn.hutool.core.io.FileUtil.file(xxurl));
sa = file.getSize();
}
if (sa > 0) {
//遍历图片数据
for (MultipartFile file : files) {
//判断上传文件格式
String fileType = file.getContentType();
log.info(file.getSize() + "");
if (("image/jpeg").equals(fileType) || ("image/png").equals(fileType) || ("image/gif").equals(fileType) || ("image/jpg").equals(fileType) || ("image/bmp").equals(fileType) || ("application/octet-stream").equals(fileType)) {
//上传后保存的文件名(需要防止图片重名导致的文件覆盖)
//获取文件名
fileName1 = file.getOriginalFilename();
String fileName;
//获取文件后缀名
try {
String suffixName = fileName1.substring(fileName1.lastIndexOf("."));
//重新生成文件名
fileName = "1" + UUID.randomUUID() + suffixName;//文件新名称
} catch (
Exception e
) {
//重新生成文件名
fileName = "1" + UUID.randomUUID() + fileName1 + ".jpg";//文件新名称
}
//设置文件存储路径,可以存放在你想要指定的路径里面
String Path = "/upload/";
String Path1 = "/opt/upload/video/"; //上传图片存放位置
zxUrl += Path + fileName + ",";
String UrlzxPath ="/opt/upload/video/";
xxurl=UrlzxPath+ fileName;
if (FileUtils.upload(file, Path1, fileName)) {
//文件存放的相对路径(一般存放在数据库用于img标签的src)
String relativePath = "用于判断是否图片上传成功,返回值有:" + fileName;
result.put("relativePath", relativePath);//前端根据是否存在该字段来判断上传是否成功
msg = "图片上传成功";
result.put("zxUrl", zxUrl);
FileOutputStream fouts = null;
Img.from(cn.hutool.core.io.FileUtil.file(xxurl))
.setQuality(0.8)//压缩比率
.write(cn.hutool.core.io.FileUtil.file(xxurl));
} else {
msg = "图片上传失败";
}
} else {
msg = "图片上传失败";
msg = "图片格式不正确";
}
} else {
msg = "图片格式不正确";
}
}
result.put("code", 0);
result.put("msg", msg);
/**
* 生成当前时间戳
*/
Long zxDate = Long.valueOf(System.currentTimeMillis());
result.put("code", 0);
result.put("msg", msg);
/**
* 生成当前时间戳
*/
Long zxDate = Long.valueOf(System.currentTimeMillis());
shopZxMapper.zxadd(zxUrl, zxField, inviteCode, zxDate);
return result;
//用户只上传文字时
}
shopZxMapper.zxadd(zxUrl, zxField, inviteCode, zxDate);
return result;
//用户只上传文字时
} else if (null != zxField && sa == 0) {
} else if (null != zxField && files == null) {
/**
* 生成当前时间戳
*/
......
......@@ -37,13 +37,9 @@ public class UploadController {
@Autowired
private UserController userController;
/**
* @param request
* @return
* @throws Exception
*/
/**
* 视频文件上传
* TODO 视频/资讯文件上传
* 资讯主键id* 视频/封面存放地址* 用户id(作者id)
* 获赞数* 视频/图片名称* 审核字段* 资讯文字输入字段
* 资讯创建时间* 图片储存地址* 资讯发表地址
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment