|
@@ -5,6 +5,7 @@ import cn.hutool.core.io.FileUtil;
|
|
|
import com.aliyun.oss.OSSClient;
|
|
|
import com.aliyun.oss.common.utils.BinaryUtil;
|
|
|
import com.aliyun.oss.model.*;
|
|
|
+import com.fdkankan.fusion.config.LaserOssConfig;
|
|
|
import com.fdkankan.fusion.response.FileInfoVo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
@@ -47,6 +48,9 @@ public class UploadToOssUtil {
|
|
|
@Autowired
|
|
|
LocalToOssUtil localToOssUtil;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ LaserOssConfig laserOssConfig;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 获取文件内容-阿里云
|
|
@@ -343,6 +347,30 @@ public class UploadToOssUtil {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ public FileInfoVo getFileInfo(String bucket,String filePath){
|
|
|
+ if("local".equals(type)){
|
|
|
+ return localToOssUtil.getFileInfo(filePath);
|
|
|
+ }
|
|
|
+ OSSClient ossClient = new OSSClient(point, key, secrey);
|
|
|
+ try {
|
|
|
+ GetObjectRequest getObjectMetadataRequest = new GetObjectRequest(bucket, filePath);
|
|
|
+ Date LastMo = ossClient.getObjectMetadata(getObjectMetadataRequest).getLastModified();
|
|
|
+ String md5 = ossClient.getObjectMetadata(getObjectMetadataRequest).getETag();
|
|
|
+ Long size = ossClient.getObjectMetadata(getObjectMetadataRequest).getContentLength();
|
|
|
+
|
|
|
+ InputStream inputStream = ossClient.getObject(bucket, filePath).getObjectContent();
|
|
|
+ String sha1 = MD5Checksum.getSHA1(inputStream);
|
|
|
+ return new FileInfoVo(md5,sha1.toUpperCase(),LastMo.getTime(),size);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("oss-getFileInfo-error:{}",filePath,e);
|
|
|
+ }finally {
|
|
|
+ if(ossClient != null){
|
|
|
+ ossClient.shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
public Long getSize(String filePath){
|
|
|
if("local".equals(type)){
|
|
|
return localToOssUtil.getSize(filePath);
|
|
@@ -370,6 +398,33 @@ public class UploadToOssUtil {
|
|
|
return total;
|
|
|
}
|
|
|
|
|
|
+ public Long getSize(String bucket,String filePath){
|
|
|
+ if("local".equals(type)){
|
|
|
+ return localToOssUtil.getSize(filePath);
|
|
|
+ }
|
|
|
+ OSSClient ossClient = new OSSClient(point, key, secrey);
|
|
|
+ Long total = 0L;
|
|
|
+ try {
|
|
|
+ List<String> files = listKeysFromAli( filePath);
|
|
|
+ if (ObjectUtils.isEmpty(files)) {
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+ for (String file : files) {
|
|
|
+ GetObjectRequest getObjectMetadataRequest = new GetObjectRequest(bucket, file);
|
|
|
+ Long size = ossClient.getObjectMetadata(getObjectMetadataRequest).getContentLength();
|
|
|
+ total += size;
|
|
|
+ }
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("oss-getFileInfo-error:{}",e);
|
|
|
+ }finally {
|
|
|
+ if(ossClient != null){
|
|
|
+ ossClient.shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return total;
|
|
|
+ }
|
|
|
+
|
|
|
public String getOssPath(String path) {
|
|
|
return path.replace(queryPath,"");
|
|
|
}
|