MinIO distributed file storage usage

MinIO distributed file storage usage

Official website address:
https://docs.minio.io/cn/
Download address for Windows:
Link: https://pan.baidu.com/s/1X2dr3r-R7mLElgTMnJCepw
Extraction code: jwo0

1. Server operation:

Enter the directory of downloaded files, enter cmd, and run the command window:

On the command line, enter:
minio.exe server the address where you want to store the file

Successful operation,

Enter the above URL in the browser to access:

The login account password is:

Login successful

2.idea end development

2.1 dependency import:

<dependency>
    <groupId>io.minio</groupId>
    <artifactId>minio</artifactId>
    <version>3.0.10</version>
</dependency>

2.2 file upload

Upload a picture case. Note that the name of the bucket cannot be minio. If you enter a sensitive word, the creation will fail

@SpringBootApplication
public class DemoApplication implements CommandLineRunner {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

	@Override
	public void run(String... args) throws Exception {
		try {
			//Use the access address and account password to establish a connection
		MinioClient minioClient = new MinioClient("http://172.16.2.14",9000,"minioadmin","minioadmin");
		//Judge whether the bucket object of file storage exists
		boolean isExist = minioClient.bucketExists("asiatrip");
		if(isExist) {
			System.out.println("Bucket asiatrip already exists.");
		} else {
			// Create a bucket named asiatrip to store zip files of photos.
			minioClient.makeBucket("asiatrip");
		}

		// Use putObject to upload a file to the bucket.
		minioClient.putObject("asiatrip","minio.png", "C:\\Users\\Administrator\\Desktop\\minio.png");
		System.out.println("Upload successful");
	} catch(MinioException e) {
		System.out.println("Error occurred: " + e);
		}
	}
}

After file upload:

2.3 upload files to the subfolder of the bucket

Subfolders are created in front of the file name, not as a suffix to the bucket
minioClient.putObject("asiatrip","ppp/minio.png", "C:\\Users\\Administrator\\Desktop\\minio.png");

2.4 file link acquisition

getObjectURL() gets the url address of the file in the bucket. If write only permission is set, the user cannot view the address directly
getObgect() can obtain the stream object of the corresponding file in the bucket for file stream transmission
presignedGetObject() returns the address of the encryption algorithm, through which you can directly access the file

Set the sharing link of validity period (the maximum time for sharing files is 7 days)
minioClient. Getpreseignedobjecturl (method. Get, "asiatrip", "Minio. PNG", 10, null) is valid for 10 seconds and can be accessed through get

3. Operation object

The classes used are MinioClient objects

3.1 operation method of storage bucket

  • makeBucket create bucket
  • listBuckets lists all current buckets
  • bucketExists determines whether the bucket exists
  • removeBucket remove bucket
  • listObjects gets the contents of the bucket
  • listIncompleteUploads obtains the content of upload interruption, and supports continuous transmission at breakpoints

3.2 document operation method

  • getObject download file
  • putObject upload file
  • copyObject copy file
  • statObject view file status
  • removeObject delete file
  • removeIncompleteUpload deletes files whose upload was interrupted

3.3 assigned operation

Signature encryption operation

  • presignedGetObject is used to obtain the get download link of files in the bucket
  • presignedPutObject is used to obtain the upload link of files in the bucket
  • presignedPostPolicy is used to set the encoding and decoding algorithm for returning and accessing links

3.4 bucket policy operation

The bucket policy is mainly to set the read-write permission. When accessing the file address, the policy will judge whether to open the corresponding function

  • getBucketPolicy get policy information
  • setBucketPolicy setting policy information

Tags: MinIO

Posted by texelate on Tue, 10 May 2022 16:37:54 +0300