|
|
@@ -1,16 +1,17 @@
|
|
|
package vip.xiaonuo.disk.util;
|
|
|
|
|
|
import io.minio.*;
|
|
|
-import io.minio.errors.ErrorResponseException;
|
|
|
-import io.minio.errors.InvalidResponseException;
|
|
|
-import io.minio.errors.XmlParserException;
|
|
|
+import io.minio.errors.*;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.io.*;
|
|
|
+import java.security.InvalidKeyException;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
@@ -49,7 +50,9 @@ public class VideoConverter {
|
|
|
String uniqueName = UUID.randomUUID() + "_" + fileName;
|
|
|
File tempFile = new File(tempDir, uniqueName);
|
|
|
try {
|
|
|
-
|
|
|
+ System.out.println("下载路径:" + tempDir);
|
|
|
+ System.out.println("下载名称:" + uniqueName);
|
|
|
+ System.out.println("下载文件:" + tempFile);
|
|
|
downloadFromMinio(minioClient, BUCKET_NAME, inputKey, tempFile);
|
|
|
filesToDelete.add(tempFile); // 添加到删除列表
|
|
|
// 执行格式转换
|
|
|
@@ -137,20 +140,25 @@ public class VideoConverter {
|
|
|
if (!client.bucketExists(BucketExistsArgs.builder().bucket(bucket).build())) {
|
|
|
client.makeBucket(MakeBucketArgs.builder().bucket(bucket).build());
|
|
|
}
|
|
|
- client.downloadObject(
|
|
|
- DownloadObjectArgs.builder()
|
|
|
- .bucket(bucket)
|
|
|
- .object(object)
|
|
|
- .filename(dest.getAbsolutePath())
|
|
|
- .build()
|
|
|
- );
|
|
|
+ try {
|
|
|
+ client.downloadObject(
|
|
|
+ DownloadObjectArgs.builder()
|
|
|
+ .bucket(bucket)
|
|
|
+ .object(object)
|
|
|
+ .filename(dest.getAbsolutePath())
|
|
|
+ .build()
|
|
|
+ );
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ System.out.println("下载失败原因=============================》" + e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private static void uploadToMinio(MinioClient client, String bucket, String object, File file) throws Exception {
|
|
|
client.uploadObject(
|
|
|
UploadObjectArgs.builder()
|
|
|
.bucket(bucket)
|
|
|
- .object("converted/" + object)
|
|
|
+ .object("converted/"+ getCurrentDate()+"/" + object)
|
|
|
.filename(file.getAbsolutePath())
|
|
|
.contentType(getMimeType(object))
|
|
|
.build()
|
|
|
@@ -325,4 +333,10 @@ public class VideoConverter {
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
+ public static String getCurrentDate() {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
+ String currentDate = sdf.format(new Date());
|
|
|
+ return currentDate;
|
|
|
+ }
|
|
|
+
|
|
|
}
|