In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to use the object storage service Minio". In the daily operation, I believe that many people have doubts about how to use the object storage service Minio. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about how to use the object storage service Minio! Next, please follow the editor to study!
Reason for recommendation
Open source free (the primary element of our consideration), high performance
Good-looking: with a beautiful interface.
Created for cloud environment: deeply integrated with K8s, etcd, docker and so on.
Documentation details: provides sdk in Java, JavaScript, Python, Golang, .net and other languages, making integration easier
Simple deployment
Docker deployment
Hang the MiniIO data and configuration folders on the host computer
Docker run-p 9090 MINIO_ACCESS_KEY=admin 9000-- name minio\-e MINIO_ACCESS_KEY=admin-e MINIO_SECRET_KEY=123123123\-v / mydata/minio/data:/data\-v / mydata/minio/config:/root/.minio\-d minio/minio server / data;# if you do not create a username password, the default username password is minioadmin:minioadmin
Visit
Springboot uses minio
1 introduction of maven
Io.minio minio 7.0.2
2 configure application.properties
Minio.url= http://192.168.3.189:9090 minio.accessKey= adminminio.secretKey= 123123123 minio.secure=false minio.bucketName=testminio.configDir=/home/data/
3 injection attribute
@ Component @ ConfigurationProperties (prefix = "minio") public class MinioConfig {/ / "endPoint is a URL, domain name, IPv4 or IPv6 address" private String url; / / ("accessKey is similar to user ID and is used to uniquely identify your account") private String accessKey; / / ("secretKey is your account password") private String secretKey; / / ("if true, use https instead of http, default is true") private Boolean secure / / ("default bucket") private String bucketName; / / ("configuration directory") private String configDir; @ Bean public MinioClient getMinioClient () throws InvalidEndpointException, InvalidPortException {MinioClient minioClient = new MinioClient (url, accessKey, secretKey,secure); return minioClient;} public String getBucketName () {return bucketName;} public String getConfigDir () {return configDir;} public String getUrl () {return url } public void setUrl (String url) {this.url = url;} public String getAccessKey () {return accessKey;} public void setAccessKey (String accessKey) {this.accessKey = accessKey;} public String getSecretKey () {return secretKey;} public void setSecretKey (String secretKey) {this.secretKey = secretKey;} public Boolean getSecure () {return secure } public void setSecure (Boolean secure) {this.secure = secure;} public void setBucketName (String bucketName) {this.bucketName = bucketName;} public void setConfigDir (String configDir) {this.configDir = configDir;}}
4 create a tool class
@ Component public class MinioUtil {@ Autowired private MinioClient minioClient; / * upload File * / public void uploadFile (InputStream inputStream, String objectName) {String buckName = "test"; try {if (! minioClient.bucketExists (buckName)) {minioClient.makeBucket (buckName) } minioClient.putObject (buckName, objectName, inputStream, inputStream.available (), "image/jpeg");} catch (Exception e) {e.printStackTrace ();}} public void downloadFile (String bucketName, String fileName, String originalName, HttpServletResponse response) {try {InputStream file = minioClient.getObject (bucketName, fileName) String filename= new String (fileName.getBytes ("ISO8859-1"), StandardCharsets.UTF_8); response.setHeader ("Content-Disposition", "attachment;filename=" + filename); ServletOutputStream servletOutputStream = response.getOutputStream (); int len; byte [] buffer = new byte [1024] While ((len = file.read (buffer)) > 0) {servletOutputStream.write (buffer, 0, len);} servletOutputStream.flush (); file.close (); servletOutputStream.close ();} catch (ErrorResponseException e) {e.printStackTrace () } catch (Exception e) {e.printStackTrace ();}
5 Test
@ RestController public class GreetingsController {@ Autowired MinioUtil minioUtil; @ RequestMapping (value = "/ {name}", method = RequestMethod.GET) @ ResponseStatus (HttpStatus.OK) public String greetingText (@ PathVariable String name,HttpServletResponse response) throws FileNotFoundException {minioUtil.uploadFile (new File ("C:\ Users\\ ctyc\\ Desktop\ 1.jpg"), "test1.jpg") MinioUtil.downloadFile ("test", "test1.jpg", "t1.jpg", response); return "Hello" + name + "!";}} at this point, the study on "how to use the object storage service Minio" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.