|
|
|
@ -11,6 +11,7 @@ import io.minio.UploadObjectArgs;
|
|
|
|
|
import io.minio.errors.*;
|
|
|
|
|
import io.minio.http.Method;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.security.InvalidKeyException;
|
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
@ -49,6 +50,7 @@ public class MinioUtils {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取文件上传签名
|
|
|
|
|
*
|
|
|
|
|
* @param objectName
|
|
|
|
|
* @return
|
|
|
|
|
* @throws ServerException
|
|
|
|
@ -95,13 +97,13 @@ public class MinioUtils {
|
|
|
|
|
public static void uploadFile(MinioClient minioClient, String key, String source) throws IOException, ServerException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
|
|
|
|
minioClient.uploadObject(
|
|
|
|
|
UploadObjectArgs.builder()
|
|
|
|
|
.bucket(PropKit.get("minio_bucketName"))
|
|
|
|
|
.bucket(PropKit.get("minio.bucketName"))
|
|
|
|
|
.object(key)
|
|
|
|
|
.filename(source)
|
|
|
|
|
.build());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
|
//加载配置文件
|
|
|
|
|
String configFile = "application_{?}.yaml".replace("{?}", getEnvPrefix());
|
|
|
|
|
PropKit = new YamlProp(configFile);
|
|
|
|
@ -117,5 +119,15 @@ public class MinioUtils {
|
|
|
|
|
System.out.println("完成全局权限设置!");
|
|
|
|
|
//测试样例
|
|
|
|
|
//http://10.10.14.212:9000/dsideal/%E5%AE%89%E5%90%89%E4%B8%BD%E5%A8%9C%E6%9C%B1%E8%8E%89.jpg
|
|
|
|
|
|
|
|
|
|
//将指定目录下的所有以png为扩展名的文件找出来,并且将图标文件上传上去
|
|
|
|
|
String path = "D:\\dsWork\\dsProject\\dsRes\\src\\main\\java\\com\\dsideal\\resource\\Util\\TuBiao";
|
|
|
|
|
File[] files = FileUtil.ls(path);
|
|
|
|
|
for (File file : files) {
|
|
|
|
|
//上传到minio
|
|
|
|
|
String objectName = "Thumbs/" + file.getName();
|
|
|
|
|
uploadFile(client, objectName, file.getAbsolutePath());
|
|
|
|
|
}
|
|
|
|
|
client.close();
|
|
|
|
|
}
|
|
|
|
|
}
|