otherContent如果content内容是图片,存宽高
This commit is contained in:
@@ -3,12 +3,19 @@ package com.peanut.modules.oss.service;
|
||||
import com.peanut.common.utils.R;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
public interface OssService {
|
||||
//上传头像到oss
|
||||
String uploadFileAvatar(MultipartFile file);
|
||||
|
||||
String uploadFileSchedule(MultipartFile file,String uid);
|
||||
|
||||
String uploadFile(File file);
|
||||
|
||||
String uploadFile(InputStream inputStream, String fileName);
|
||||
|
||||
String uploadHtml(String html,String name);
|
||||
|
||||
R getSchedule(String uid);
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -76,6 +77,49 @@ public class OssServiceImpl implements OssService {
|
||||
}
|
||||
}
|
||||
|
||||
public String uploadFile(File file) {
|
||||
String endpoint = ConstantPropertiesUtils.END_POIND;
|
||||
String accessKeyId = ConstantPropertiesUtils.ACCESS_KEY_ID;
|
||||
String accessKeySecret = ConstantPropertiesUtils.ACCESS_KEY_SECRET;
|
||||
String bucketName = ConstantPropertiesUtils.BUCKET_NAME;
|
||||
try {
|
||||
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
String fileName = file.getName();
|
||||
fileName = uuid + fileName;
|
||||
String datePath = new DateTime().toString("yyyy/MM/dd");
|
||||
fileName = datePath + "/" + fileName;
|
||||
ossClient.putObject(bucketName, fileName, file);
|
||||
ossClient.shutdown();
|
||||
String url = "https://" + bucketName + "." + endpoint + "/" + fileName;
|
||||
return url;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String uploadFile(InputStream inputStream, String fileName) {
|
||||
String endpoint = ConstantPropertiesUtils.END_POIND;
|
||||
String accessKeyId = ConstantPropertiesUtils.ACCESS_KEY_ID;
|
||||
String accessKeySecret = ConstantPropertiesUtils.ACCESS_KEY_SECRET;
|
||||
String bucketName = ConstantPropertiesUtils.BUCKET_NAME;
|
||||
try {
|
||||
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
fileName = uuid + fileName;
|
||||
String datePath = new DateTime().toString("yyyy/MM/dd");
|
||||
fileName = datePath + "/" + fileName;
|
||||
ossClient.putObject(bucketName, fileName, inputStream);
|
||||
ossClient.shutdown();
|
||||
String url = "https://" + bucketName + "." + endpoint + "/" + fileName;
|
||||
return url;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uploadHtml(String html, String name) {
|
||||
// 工具类获取值
|
||||
|
||||
Reference in New Issue
Block a user