静态图片上传、文件大小限制
This commit is contained in:
parent
a51cd7d5a5
commit
aef9e13b78
@ -3,6 +3,11 @@ server:
|
|||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: ebike-gateway
|
name: ebike-gateway
|
||||||
|
servlet:
|
||||||
|
multipart:
|
||||||
|
max-file-size: 30MB
|
||||||
|
max-request-size: 100MB
|
||||||
|
file-size-threshold: 0B
|
||||||
jackson:
|
jackson:
|
||||||
serialization:
|
serialization:
|
||||||
write-dates-as-timestamps: false
|
write-dates-as-timestamps: false
|
||||||
|
|||||||
@ -3,6 +3,11 @@ server:
|
|||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: ebike-operations
|
name: ebike-operations
|
||||||
|
servlet:
|
||||||
|
multipart:
|
||||||
|
max-file-size: 30MB
|
||||||
|
max-request-size: 100MB
|
||||||
|
file-size-threshold: 0B
|
||||||
cloud:
|
cloud:
|
||||||
nacos:
|
nacos:
|
||||||
server-addr: 127.0.0.1:8848 # nacos
|
server-addr: 127.0.0.1:8848 # nacos
|
||||||
|
|||||||
@ -3,6 +3,11 @@ server:
|
|||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: ebike-payment
|
name: ebike-payment
|
||||||
|
servlet:
|
||||||
|
multipart:
|
||||||
|
max-file-size: 30MB
|
||||||
|
max-request-size: 100MB
|
||||||
|
file-size-threshold: 0B
|
||||||
cloud:
|
cloud:
|
||||||
nacos:
|
nacos:
|
||||||
server-addr: 127.0.0.1:8848 # nacos
|
server-addr: 127.0.0.1:8848 # nacos
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import com.cdzy.common.model.response.JsonResult;
|
|||||||
import com.cdzy.staff.model.entity.EbikeImg;
|
import com.cdzy.staff.model.entity.EbikeImg;
|
||||||
import com.cdzy.staff.service.EbikeImgService;
|
import com.cdzy.staff.service.EbikeImgService;
|
||||||
import com.mybatisflex.core.paginate.Page;
|
import com.mybatisflex.core.paginate.Page;
|
||||||
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
|
import io.netty.util.internal.StringUtil;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@ -14,6 +16,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.cdzy.staff.model.entity.table.EbikeImgTableDef.EBIKE_IMG;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 图片表 控制层。
|
* 图片表 控制层。
|
||||||
*
|
*
|
||||||
@ -36,6 +40,8 @@ public class EbikeImgController {
|
|||||||
@PostMapping("save")
|
@PostMapping("save")
|
||||||
public JsonResult<?> save(@RequestBody @Validated EbikeImg ebikeImg) {
|
public JsonResult<?> save(@RequestBody @Validated EbikeImg ebikeImg) {
|
||||||
ebikeImg.setCreatedBy(StpUtil.getLoginIdAsLong());
|
ebikeImg.setCreatedBy(StpUtil.getLoginIdAsLong());
|
||||||
|
String nameWithoutExtension = StringUtil.substringBefore(ebikeImg.getFileUrl(), '.');
|
||||||
|
ebikeImg.setImgCode(nameWithoutExtension);
|
||||||
ebikeImgService.save(ebikeImg);
|
ebikeImgService.save(ebikeImg);
|
||||||
return JsonResult.success();
|
return JsonResult.success();
|
||||||
}
|
}
|
||||||
@ -82,8 +88,10 @@ public class EbikeImgController {
|
|||||||
* @return 分页对象
|
* @return 分页对象
|
||||||
*/
|
*/
|
||||||
@GetMapping("page")
|
@GetMapping("page")
|
||||||
public JsonResult<Page<EbikeImg>> page(PageParam pageParam) {
|
public JsonResult<Page<EbikeImg>> page(PageParam pageParam,String imgName) {
|
||||||
Page<EbikeImg> page = ebikeImgService.page(pageParam.getPage());
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||||
|
.where(EBIKE_IMG.IMG_NAME.like(imgName,StringUtil.isNullOrEmpty(imgName)));
|
||||||
|
Page<EbikeImg> page = ebikeImgService.page(pageParam.getPage(),queryWrapper);
|
||||||
return JsonResult.success(page);
|
return JsonResult.success(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,8 +103,8 @@ public class EbikeImgController {
|
|||||||
* @return 操作结果
|
* @return 操作结果
|
||||||
*/
|
*/
|
||||||
@PostMapping("upload")
|
@PostMapping("upload")
|
||||||
public JsonResult<?> upload(@RequestParam("file") MultipartFile file) throws Exception {
|
public JsonResult<?> upload(@RequestParam("file") MultipartFile file,String imgCode) throws Exception {
|
||||||
String result = ebikeImgService.upload(file);
|
String result = ebikeImgService.upload(file,imgCode);
|
||||||
return JsonResult.success(Message.SUCCESS, result);
|
return JsonResult.success(Message.SUCCESS, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -41,7 +41,6 @@ public class EbikeImg implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 唯一分区编码
|
* 唯一分区编码
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "图片标识不能为空")
|
|
||||||
private String imgCode;
|
private String imgCode;
|
||||||
|
|
||||||
@Column(onInsertValue = "now()")
|
@Column(onInsertValue = "now()")
|
||||||
|
|||||||
@ -17,5 +17,5 @@ public interface EbikeImgService extends IService<EbikeImg> {
|
|||||||
* @param file 文件
|
* @param file 文件
|
||||||
* @return 路径
|
* @return 路径
|
||||||
*/
|
*/
|
||||||
String upload(MultipartFile file) throws Exception;
|
String upload(MultipartFile file,String imgCode) throws Exception;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import com.cdzy.staff.mapper.EbikeImgMapper;
|
|||||||
import com.cdzy.staff.model.entity.EbikeImg;
|
import com.cdzy.staff.model.entity.EbikeImg;
|
||||||
import com.cdzy.staff.service.EbikeImgService;
|
import com.cdzy.staff.service.EbikeImgService;
|
||||||
import com.cdzy.staff.utils.MinioUtil;
|
import com.cdzy.staff.utils.MinioUtil;
|
||||||
|
import com.mybatisflex.core.util.StringUtil;
|
||||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -28,9 +29,10 @@ public class EbikeImgServiceImpl extends ServiceImpl<EbikeImgMapper, EbikeImg>
|
|||||||
MinioUtil minioUtil;
|
MinioUtil minioUtil;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String upload(MultipartFile file) throws Exception {
|
public String upload(MultipartFile file,String imgCode) throws Exception {
|
||||||
String objectName = imageUrl + UUID.randomUUID().toString().replace("-", "") + "." + FileNameUtil.extName(file.getOriginalFilename());
|
String result = StringUtil.hasText(imgCode) ?imgCode:UUID.randomUUID().toString().replace("-", "") + "." + FileNameUtil.extName(file.getOriginalFilename());
|
||||||
|
String objectName = imageUrl + result;
|
||||||
minioUtil.uploadFile(file.getInputStream(), objectName);
|
minioUtil.uploadFile(file.getInputStream(), objectName);
|
||||||
return minioUtil.getShowUrl(objectName);
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,11 @@ server:
|
|||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: ebike-staff
|
name: ebike-staff
|
||||||
|
servlet:
|
||||||
|
multipart:
|
||||||
|
max-file-size: 30MB
|
||||||
|
max-request-size: 100MB
|
||||||
|
file-size-threshold: 0B
|
||||||
cloud:
|
cloud:
|
||||||
nacos:
|
nacos:
|
||||||
server-addr: 127.0.0.1:8848 # nacos
|
server-addr: 127.0.0.1:8848 # nacos
|
||||||
|
|||||||
@ -1,6 +1,11 @@
|
|||||||
server:
|
server:
|
||||||
port: 10014
|
port: 10014
|
||||||
spring:
|
spring:
|
||||||
|
servlet:
|
||||||
|
multipart:
|
||||||
|
max-file-size: 30MB
|
||||||
|
max-request-size: 100MB
|
||||||
|
file-size-threshold: 0B
|
||||||
application:
|
application:
|
||||||
name: ebike-user
|
name: ebike-user
|
||||||
cloud:
|
cloud:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user