How to integrate Object Storage with Java?
Certainly! Here are detailed steps for setting up and using Minio Cluster on AccuWeb.Cloud, integrating it with a Java project, and managing file uploads:
Step-by-Step Guide
Step 1. Log in to AccuWeb.Cloud Dashboard
- Navigate to AccuWeb.Cloud: Open your web browser and go to AccuWeb.Cloud.
- Login: Enter your credentials (username and password) to access your AccuWeb.Cloud dashboard.
Step 2. Install Minio Cluster from Marketplace
- Go to Marketplace: Locate and click on “Marketplace” in your AccuWeb.Cloud dashboard.
- Search and Install Minio Cluster: In the Marketplace, navigate to “Storage & File” and search for Minio Cluster. Install it following the prompts.
Step 3. Configure Minio Cluster
- Configure Minio Cluster: After installation, configure your Minio Cluster by specifying:
-
- Number of nodes (e.g., 1 node for demo purposes)
- Environment name (e.g., minio-cluster-demo)
- Display name (e.g., Minio Cluster Demo)
- Region (e.g., US)
Step 4. Retrieve Minio Cluster Credentials
- Check Email: Check your registered email for the Minio Cluster admin panel URL, Access Key, and Secret Key provided after installation.
Step 5. Login to Minio Cluster
- Access Minio Cluster: Using the credentials received, log in to the Minio Cluster admin panel.
Step 6. Create a Bucket
- Create Bucket: Within the Minio Cluster admin panel, create a new bucket for storing files.
Step 7. Access File Storage in Bucket
- Upload and View Files: Upload files to your created bucket. Verify successful upload by checking the file list within the bucket.
Step 8. Set up MinIO Java SDK
Add the MinIO Java SDK dependency to your pom.xml:
<!-- MinIO dependency -->
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.2.2</version>
</dependency>
Step 9. Configure MinioConfig.java File
package com.example.fileupload.config;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MinioConfig {
@Value("${minio.url}")
private String minioUrl;
@Value("${minio.accessKey}")
private String accessKey;
@Value("${minio.secretKey}")
private String secretKey;
@Bean
public MinioClient minioClient() {
return MinioClient.builder()
.endpoint(minioUrl)
.credentials(accessKey, secretKey)
.build();
}
}
Step 10. Upload Files in java Controller
@Autowired
private MinioClient minioClient;
@Value("${minio.bucketName}")
private String bucketName;
public String uploadFile(@RequestParam("file") MultipartFile file) {
try {
String fileName = file.getOriginalFilename();
minioClient.putObject(
PutObjectArgs.builder()
.bucket(bucketName)
.object(fileName)
.stream(file.getInputStream(), file.getSize(), -1)
.contentType(file.getContentType())
.build()
);
return fileName;
} catch (MinioException | IOException e) {
throw new RuntimeException("Error occurred while uploading file to MinIO", e);
}
}
Step 11. View the Uploaded File in Minio Bucket
- Verify File Upload: After uploading a file using your Laravel application, verify that it appears in your Minio bucket.






