mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-15 15:28:41 +08:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
@@ -12,17 +12,13 @@ import com.jsowell.framework.config.ServerConfig;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.*;
|
||||||
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.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -205,6 +201,7 @@ public class CommonController {
|
|||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@PostMapping("/uploadOSS")
|
@PostMapping("/uploadOSS")
|
||||||
public AjaxResult uploadFileOSS(MultipartFile file) throws Exception {
|
public AjaxResult uploadFileOSS(MultipartFile file) throws Exception {
|
||||||
|
log.info("上传到阿里云oss, 文件大小:{}", getSize(file.getSize()));
|
||||||
try {
|
try {
|
||||||
String url = AliyunOssUploadUtils.uploadFile(file);
|
String url = AliyunOssUploadUtils.uploadFile(file);
|
||||||
AjaxResult ajax = AjaxResult.success();
|
AjaxResult ajax = AjaxResult.success();
|
||||||
@@ -212,7 +209,7 @@ public class CommonController {
|
|||||||
ajax.put("fileName", FileUtils.getName(url));
|
ajax.put("fileName", FileUtils.getName(url));
|
||||||
ajax.put("newFileName", FileUtils.getName(url));
|
ajax.put("newFileName", FileUtils.getName(url));
|
||||||
ajax.put("originalFilename", file.getOriginalFilename());
|
ajax.put("originalFilename", file.getOriginalFilename());
|
||||||
log.info("图片上传成功 url:{}", url);
|
log.info("上传到阿里云oss, 图片上传成功 url:{}", url);
|
||||||
return ajax;
|
return ajax;
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
log.error("上传到阿里云oss error, ", 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
|
* 上传蓝牙升级程序到阿里云oss
|
||||||
* http://localhost:8080/common/uploadBlueToothFile2OSS
|
* http://localhost:8080/common/uploadBlueToothFile2OSS
|
||||||
|
|||||||
Reference in New Issue
Block a user