方法:
public void uploadFile(String fileUrl, String bucketName, String objectName) throws IOException, MinioException, NoSuchAlgorithmException, InvalidKeyException {
System.out.println("Uploading file from URL: " + fileUrl);
System.out.println("Object name: " + objectName);
try (InputStream inputStream = new URL(fileUrl).openStream()) {
// 获取文件大小
HttpURLConnection connection = (HttpURLConnection) new URL(fileUrl).openConnection();
connection.setRequestMethod("HEAD");
long fileSize = connection.getContentLengthLong();
// 上传文件到 MinIO
minioClient.putObject(bucketName, objectName, inputStream, new PutObjectOptions(fileSize, -1)); // 使用文件大小作为部分大小
System.out.println("File uploaded successfully from URL: " + fileUrl);
} catch (IOException e) {
e.printStackTrace();
System.out.println("Failed to uplo