Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
YAS\29473
2025-12-09 16:18:02 +08:00

View File

@@ -12,17 +12,13 @@ import com.jsowell.framework.config.ServerConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
@@ -205,6 +201,7 @@ public class CommonController {
@CrossOrigin
@PostMapping("/uploadOSS")
public AjaxResult uploadFileOSS(MultipartFile file) throws Exception {
log.info("上传到阿里云oss, 文件大小:{}", getSize(file.getSize()));
try {
String url = AliyunOssUploadUtils.uploadFile(file);
AjaxResult ajax = AjaxResult.success();
@@ -212,7 +209,7 @@ public class CommonController {
ajax.put("fileName", FileUtils.getName(url));
ajax.put("newFileName", FileUtils.getName(url));
ajax.put("originalFilename", file.getOriginalFilename());
log.info("图片上传成功 url:{}", url);
log.info("上传到阿里云oss, 图片上传成功 url:{}", url);
return ajax;
}catch (Exception e){
log.error("上传到阿里云oss error, ", e);
@@ -220,6 +217,34 @@ public class CommonController {
}
}
/**
* 获取文件大小
*
* @param size
* @return
*/
public static String getSize(long size) {
StringBuilder bytes = new StringBuilder();
DecimalFormat format = new DecimalFormat("###.0");
if (size >= 1024 * 1024 * 1024) {
double i = (size / (1024.0 * 1024.0 * 1024.0));
bytes.append(format.format(i)).append("GB");
} else if (size >= 1024 * 1024) {
double i = (size / (1024.0 * 1024.0));
bytes.append(format.format(i)).append("MB");
} else if (size >= 1024) {
double i = (size / (1024.0));
bytes.append(format.format(i)).append("KB");
} else {
if (size <= 0) {
bytes.append("0B");
} else {
bytes.append((int) size).append("B");
}
}
return bytes.toString();
}
/**
* 上传蓝牙升级程序到阿里云oss
* http://localhost:8080/common/uploadBlueToothFile2OSS