图片控制
This commit is contained in:
@@ -355,7 +355,14 @@ public class ARMerchantManager {
|
|||||||
private String imgToBase64(String imgUrl) {
|
private String imgToBase64(String imgUrl) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return Base64.getEncoder().encodeToString(IOUtils.toByteArray(new URL(imgUrl).openStream()));
|
URL url = new URL(imgUrl);
|
||||||
|
byte[] imageBytes = IOUtils.toByteArray(url.openStream());
|
||||||
|
double sizeInMB = imageBytes.length / (1024.0 * 1024.0);
|
||||||
|
if (sizeInMB > 2) {
|
||||||
|
log.error("图片大小超过2MB,请重新上传");
|
||||||
|
throw new RuntimeException("图片大小超过2MB,请重新上传");
|
||||||
|
}
|
||||||
|
return Base64.getEncoder().encodeToString(IOUtils.toByteArray(url.openStream()));
|
||||||
}catch (IOException e){
|
}catch (IOException e){
|
||||||
log.error("图片转base64失败:{}",e.getMessage());
|
log.error("图片转base64失败:{}",e.getMessage());
|
||||||
throw new RuntimeException("图片转base64失败");
|
throw new RuntimeException("图片转base64失败");
|
||||||
|
|||||||
Reference in New Issue
Block a user