Commit c800c51e authored by m1991's avatar m1991

资讯模块数据——视频功能修复

parent f89c1ddf
package cn.wisenergy.common.config;
/**
* Created by m1991 on 2021/3/10 17:27
*/
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
@Configuration
public class UploadConfig {
//显示声明CommonsMultipartResolver为mutipartResolver
@Bean(name = "multipartResolver")
public MultipartResolver multipartResolver() {
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
resolver.setDefaultEncoding("UTF-8");
//resolveLazily属性启用是为了推迟文件解析,以在在UploadAction中捕获文件大小异常
resolver.setResolveLazily(true);
resolver.setMaxInMemorySize(40960);
//上传文件大小 5M 5*1024*1024
resolver.setMaxUploadSize(5 * 1024 * 1024);
return resolver;
}
}
......@@ -39,6 +39,10 @@ public interface UploadService {
* @return
*/
List imageUpload( MultipartFile[] file, String zxField, String zxAddress,String inviteCode);
String storeFile(MultipartFile file);
Resource loadFileAsResource(String fileName);
......
......@@ -106,7 +106,7 @@ public class UploadServiceImpl implements UploadService {
Long zxDate= Long.valueOf(System.currentTimeMillis());
String basePath = request.getScheme() + "://" + request.getServerName()
+ ":" + request.getServerPort()+"/mimi/upload/images/";
+ ":" + request.getServerPort()+"/mimi/upload/";
Long time = System.currentTimeMillis();
......@@ -137,11 +137,6 @@ public class UploadServiceImpl implements UploadService {
@Override
public List imageUpload(MultipartFile[] files, String zxField, String zxAddress,String inviteCode) {
/**
* 生成当前时间戳
*/
Long zxDate= Long.valueOf(System.currentTimeMillis());
//获取上传图片数量,打印在控制台
System.out.println("上传图片数量" + files.length);
//创建集合
......@@ -163,7 +158,7 @@ public class UploadServiceImpl implements UploadService {
String fileType = file.getContentType();
if (fileType.equals("image/jpeg") || fileType.equals("image/png")) {
// 要上传的目标文件存放的绝对路径
String rootPath="D:/mimi/upload/images/"; //上传图片存放位置
//上传后保存的文件名(需要防止图片重名导致的文件覆盖)
//获取文件名
fileName = file.getOriginalFilename();
......@@ -173,6 +168,7 @@ public class UploadServiceImpl implements UploadService {
fileName = UUID.randomUUID() + suffixName;
zxUrl+=localPath+fileName+",";
zxUrl.replaceAll("\\\\","");
// shopZxMapper.zxadd(zxUrl,userId,zxName,zxField,imgUrl,zxAddress);
if (FileUtils.upload(file, localPath, fileName)) {
//文件存放的相对路径(一般存放在数据库用于img标签的src)
......@@ -194,6 +190,10 @@ public class UploadServiceImpl implements UploadService {
String root_json = JSON.toJSONString(root);
System.out.println(root_json);
result.put("returnCode", 0);
/**
* 生成当前时间戳
*/
Long zxDate= Long.valueOf(System.currentTimeMillis());
shopZxMapper.zxadd(zxUrl,zxField,zxAddress,inviteCode, zxDate);
return root;
}
......
package cn.wisenergy;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching;
......
......@@ -94,7 +94,7 @@ public class UploadController {
@ApiImplicitParam(name = "inviteCode", value = "用户本人邀请码(发布人)", required = true, dataType = "String")})
@RequestMapping(method = RequestMethod.POST, value = "/multipleImageUpload", headers = "content-type=multipart/form-data")
public List multipleImageUpload(@RequestParam(value = "files") MultipartFile[] files, String zxField, String zxAddress,String inviteCode) {
public List multipleImageUpload(@RequestParam(required=false,value = "files") MultipartFile[] files, String zxField, String zxAddress,String inviteCode) {
return uploadService.imageUpload(files, zxField, zxAddress,inviteCode);
}
......
......@@ -62,7 +62,7 @@ uploadFile:
location: /opt/images/upload_flowChart/ #自定义上传文件服务器硬盘保存路径 ,linux服务器保存路径 /home/changfa/app/wxbjgkpt/upload_flowChart/
file:
upload:
path: /opt/upload/video/
path: /opt/upload/
jwt:
# 加密秘钥
secret: f4e2e52034348f86b67cde581c0f9eb5
......
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