main
黄海 9 months ago
parent 7b9ae8e193
commit 38a66ee4e4

@ -11,6 +11,7 @@ import io.minio.UploadObjectArgs;
import io.minio.errors.*; import io.minio.errors.*;
import io.minio.http.Method; import io.minio.http.Method;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@ -49,6 +50,7 @@ public class MinioUtils {
/** /**
* *
*
* @param objectName * @param objectName
* @return * @return
* @throws ServerException * @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 { public static void uploadFile(MinioClient minioClient, String key, String source) throws IOException, ServerException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
minioClient.uploadObject( minioClient.uploadObject(
UploadObjectArgs.builder() UploadObjectArgs.builder()
.bucket(PropKit.get("minio_bucketName")) .bucket(PropKit.get("minio.bucketName"))
.object(key) .object(key)
.filename(source) .filename(source)
.build()); .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()); String configFile = "application_{?}.yaml".replace("{?}", getEnvPrefix());
PropKit = new YamlProp(configFile); PropKit = new YamlProp(configFile);
@ -117,5 +119,15 @@ public class MinioUtils {
System.out.println("完成全局权限设置!"); 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 //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();
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Loading…
Cancel
Save