Browse Source

fix: 拍照上传失败的bug

master
xsx 2 years ago
parent
commit
2e7a456fee
  1. 4
      im-platform/src/main/java/com/bx/implatform/contant/Constant.java
  2. 4
      im-platform/src/main/java/com/bx/implatform/service/thirdparty/FileService.java
  3. 23
      im-uniapp/components/image-upload/image-upload.vue

4
im-platform/src/main/java/com/bx/implatform/contant/Constant.java

@ -8,11 +8,11 @@ public final class Constant {
/**
* 最大图片上传大小
*/
public static final long MAX_IMAGE_SIZE = 5 * 1024 * 1024;
public static final long MAX_IMAGE_SIZE = 20 * 1024 * 1024;
/**
* 最大上传文件大小
*/
public static final long MAX_FILE_SIZE = 10 * 1024 * 1024;
public static final long MAX_FILE_SIZE = 20 * 1024 * 1024;
/**
* 群聊最大人数
*/

4
im-platform/src/main/java/com/bx/implatform/service/thirdparty/FileService.java

@ -59,7 +59,7 @@ public class FileService {
Long userId = SessionContext.getSession().getUserId();
// 大小校验
if (file.getSize() > Constant.MAX_FILE_SIZE) {
throw new GlobalException(ResultCode.PROGRAM_ERROR, "文件大小不能超过10M");
throw new GlobalException(ResultCode.PROGRAM_ERROR, "文件大小不能超过20M");
}
// 上传
String fileName = minioUtil.upload(bucketName, filePath, file);
@ -76,7 +76,7 @@ public class FileService {
Long userId = SessionContext.getSession().getUserId();
// 大小校验
if (file.getSize() > Constant.MAX_IMAGE_SIZE) {
throw new GlobalException(ResultCode.PROGRAM_ERROR, "图片大小不能超过5M");
throw new GlobalException(ResultCode.PROGRAM_ERROR, "图片大小不能超过20M");
}
// 图片格式校验
if (!FileUtil.isImage(file.getOriginalFilename())) {

23
im-uniapp/components/image-upload/image-upload.vue

@ -50,13 +50,7 @@
sizeType: ['original'], //original compressed
success: (res) => {
res.tempFiles.forEach((file) => {
//
if (this.maxSize && file.size > this.maxSize) {
this.$message.error(`文件大小不能超过 ${this.fileSizeStr}!`);
this.$emit("fail", file);
return;
}
console.log("文件:",file)
if (!this.onBefore || this.onBefore(file)) {
//
this.uploadImage(file);
@ -76,6 +70,10 @@
success: (res) => {
let data = JSON.parse(res.data);
if(data.code != 200){
uni.showToast({
icon: "none",
title: data.message,
})
this.onError && this.onError(file, data);
}else{
this.onSuccess && this.onSuccess(file, data);
@ -87,17 +85,6 @@
}
})
}
},
computed: {
fileSizeStr() {
if (this.maxSize > 1024 * 1024) {
return Math.round(this.maxSize / 1024 / 1024) + "M";
}
if (this.maxSize > 1024) {
return Math.round(this.maxSize / 1024) + "KB";
}
return this.maxSize + "B";
}
}
}
</script>

Loading…
Cancel
Save