├── .gitignore ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── README.md ├── data ├── .minio.sys │ ├── buckets │ │ ├── .bloomcycle.bin │ │ ├── .minio.sys │ │ │ └── buckets │ │ │ │ ├── .usage-cache.bin │ │ │ │ └── fs.json │ │ │ │ ├── commons │ │ │ │ └── .usage-cache.bin │ │ │ │ │ └── fs.json │ │ │ │ └── test1 │ │ │ │ └── .usage-cache.bin │ │ │ │ └── fs.json │ │ ├── .tracker.bin │ │ ├── .usage-cache.bin │ │ ├── .usage.json │ │ └── commons │ │ │ ├── .metadata.bin │ │ │ ├── .usage-cache.bin │ │ │ ├── 241a819241814e389548633d8402a99f.PNG │ │ │ └── fs.json │ │ │ └── ad94ff2e9b404772a1f9b98f4e11b4f9.PNG │ │ │ └── fs.json │ ├── config │ │ ├── config.json │ │ └── iam │ │ │ └── format.json │ └── format.json └── commons │ ├── 241a819241814e389548633d8402a99f.PNG │ └── ad94ff2e9b404772a1f9b98f4e11b4f9.PNG ├── docker-compose.yml ├── mvnw ├── mvnw.cmd ├── pom.xml ├── screenshots ├── screenshot_1.PNG ├── screenshot_10.PNG ├── screenshot_11.PNG ├── screenshot_12.PNG ├── screenshot_13.PNG ├── screenshot_14.PNG ├── screenshot_15.PNG ├── screenshot_16.PNG ├── screenshot_17.PNG ├── screenshot_18.PNG ├── screenshot_19.PNG ├── screenshot_2.PNG ├── screenshot_20.PNG ├── screenshot_3.PNG ├── screenshot_4.PNG ├── screenshot_5.PNG ├── screenshot_6.PNG ├── screenshot_7.PNG ├── screenshot_8.PNG ├── screenshot_9.PNG └── springboot_minio.png └── src ├── main ├── java │ └── com │ │ └── springminio │ │ └── app │ │ ├── AppApplication.java │ │ ├── aop │ │ └── MinioServiceImplAspect.java │ │ ├── config │ │ ├── MinioConfig.java │ │ └── SwaggerConfig.java │ │ ├── controller │ │ └── MinioController.java │ │ ├── exception │ │ ├── ApiError.java │ │ ├── FileResponseException.java │ │ └── error │ │ │ └── GlobalExceptionHandler.java │ │ ├── payload │ │ └── FileResponse.java │ │ ├── service │ │ ├── MinioService.java │ │ └── impl │ │ │ └── MinioServiceImpl.java │ │ └── util │ │ ├── FileTypeUtils.java │ │ └── MinioUtil.java └── resources │ └── application.yml └── test └── java └── com └── springminio └── app └── AppApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.3/apache-maven-3.8.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Minio 2 | 3 | Main Information 4 | 5 | ### 📖 Information 6 | 7 | 25 | 26 | ### 🔨 Run the App 27 | 28 | 1 ) Install Docker Desktop. Here is the installation link : https://docs.docker.com/docker-for-windows/install/ 29 | 30 | 2 ) Open Terminal under resources folder to run Minio on Docker Container 31 | ``` 32 | docker-compose up -d 33 | ``` 34 | 3 ) Open Minio in the Browser 35 | ``` 36 | 127.0.0.1:9001 37 | ``` 38 | 4 ) Enter username and password 39 | ``` 40 | username : minioadmin 41 | password : minioadmin 42 | ``` 43 | 5 ) Explore Rest APIs 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 |
MethodUrlDescriptionValid Request BodyValid Request Params
POST/uploadUpload file to MinioInfo
POST/addBucket/{bucketName}Add BucketName in MinioInfo
GET/show/{bucketName}Show defined Bucketname by its name in MinioInfo
GET/showBucketNameShow all BucketNames in MinioInfo
DELETE/removeBucket/{bucketName}Delete defined bucketname from MinioInfo
DELETE/removeObject/{bucketName}/{objectName}Delete defined object in defined bucketname from MinioInfo
DELETE/removeListObject/{bucketName}Remove object list in defined bucketname from MinioInfo
GET/showListObjectNameAndDownloadUrl/{bucketName}List object names and its download url in defined bucketname of MinioInfo
GET/download/{bucketName}/{objectName}Download object in BucketName from MinioInfo
116 | 117 | ### Used Dependencies 118 | * Spring Boot Web 119 | * Minio 120 | * Lombok 121 | * AspectJ 122 | * Apache Commons Lang 123 | * Swagger 124 | 125 | ## Swagger 126 | > **Access : http://localhost:8085/swagger-ui.html** 127 | 128 | ## Valid Request Body 129 | 130 | ##### Upload -> http://localhost:8085/minio/upload 131 | ``` 132 | file : Uploaded File 133 | bucketname : commons 134 | ``` 135 | 136 | ##### Delete List Object-> http://localhost:8085/minio/removeListObject/{bucketName} 137 | ``` 138 | [ 139 | "de43ab54e89f4879a2baf87df1570f56.PNG", 140 | "f107737d21534f42a72dcf009a64a07d.PNG" 141 | ] 142 | ``` 143 | 144 | ## Valid Request Params 145 | 146 | ##### Add Bucket Name -> http://localhost:8085/minio/addBucket/{bucketName} 147 | ``` 148 | http://localhost:8085/minio/addBucket/test1 149 | ``` 150 | 151 | ##### Show Bucket Name -> http://localhost:8085/minio/show/{bucketName} 152 | ``` 153 | http://localhost:8085/minio/show/commons 154 | ``` 155 | 156 | ##### Show All Bucket Names -> http://localhost:8085/minio/showBucketName 157 | ``` 158 | http://localhost:8085/minio/showBucketName 159 | ``` 160 | 161 | ##### Delete Bucket Name -> http://localhost:8085/minio/removeBucket/{bucketName} 162 | ``` 163 | http://localhost:8085/minio/removeBucket/test1 164 | ``` 165 | 166 | ##### List Object Information -> http://localhost:8085/minio/showListObjectNameAndDownloadUrl/{bucketName} 167 | ``` 168 | http://localhost:8085/minio/removeBucket/test1 169 | ``` 170 | 171 | ##### Download File -> http://localhost:8085/minio/download/{bucketName}/{objectName} 172 | ``` 173 | http://localhost:8085/minio/download/commons/ad94ff2e9b404772a1f9b98f4e11b4f9.PNG 174 | ``` 175 | 176 | ##### Delete File from Bucket Name -> http://localhost:8085/minio/removeObject/{bucketName}/{objectName} 177 | ``` 178 | http://localhost:8085/minio/removeObject/commons/a2d203e188f94ccb8393e688deaf216a.jpg 179 | ``` 180 | 181 | ### Screenshots 182 | 183 |
184 | Click here to show the screenshots of project 185 |

Figure 1

186 | 187 |

Figure 2

188 | 189 |

Figure 3

190 | 191 |

Figure 4

192 | 193 |

Figure 5

194 | 195 |

Figure 6

196 | 197 |

Figure 7

198 | 199 |

Figure 8

200 | 201 |

Figure 9

202 | 203 |

Figure 10

204 | 205 |

Figure 11

206 | 207 |

Figure 12

208 | 209 |

Figure 13

210 | 211 |

Figure 14

212 | 213 |

Figure 15

214 | 215 |

Figure 16

216 | 217 |

Figure 17

218 | 219 |

Figure 18

220 | 221 |

Figure 19

222 | 223 |

Figure 20

224 | 225 |
-------------------------------------------------------------------------------- /data/.minio.sys/buckets/.bloomcycle.bin: -------------------------------------------------------------------------------- 1 | ; -------------------------------------------------------------------------------- /data/.minio.sys/buckets/.minio.sys/buckets/.usage-cache.bin/fs.json: -------------------------------------------------------------------------------- 1 | {"version":"1.0.2","checksum":{"algorithm":"","blocksize":0,"hashes":null},"meta":{"etag":"076e76afe84251abdb61671ad505cdcd"}} -------------------------------------------------------------------------------- /data/.minio.sys/buckets/.minio.sys/buckets/commons/.usage-cache.bin/fs.json: -------------------------------------------------------------------------------- 1 | {"version":"1.0.2","checksum":{"algorithm":"","blocksize":0,"hashes":null},"meta":{"etag":"41c6457d34057b83853ad81842eac558"}} -------------------------------------------------------------------------------- /data/.minio.sys/buckets/.minio.sys/buckets/test1/.usage-cache.bin/fs.json: -------------------------------------------------------------------------------- 1 | {"version":"1.0.2","checksum":{"algorithm":"","blocksize":0,"hashes":null},"meta":{"etag":"f026a9f4e72f8d804e01dbe8944d12f3"}} -------------------------------------------------------------------------------- /data/.minio.sys/buckets/.tracker.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/data/.minio.sys/buckets/.tracker.bin -------------------------------------------------------------------------------- /data/.minio.sys/buckets/.usage-cache.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/data/.minio.sys/buckets/.usage-cache.bin -------------------------------------------------------------------------------- /data/.minio.sys/buckets/.usage.json: -------------------------------------------------------------------------------- 1 | {"lastUpdate":"2022-01-22T23:31:39.6261497Z","objectsCount":2,"objectsTotalSize":61309,"objectsReplicationInfo":null,"bucketsCount":1,"bucketsUsageInfo":{"commons":{"size":61309,"objectsPendingReplicationTotalSize":0,"objectsFailedReplicationTotalSize":0,"objectsReplicatedTotalSize":0,"objectsPendingReplicationCount":0,"objectsFailedReplicationCount":0,"objectsCount":2,"objectsSizesHistogram":{"BETWEEN_1024_B_AND_1_MB":2,"BETWEEN_10_MB_AND_64_MB":0,"BETWEEN_128_MB_AND_512_MB":0,"BETWEEN_1_MB_AND_10_MB":0,"BETWEEN_64_MB_AND_128_MB":0,"GREATER_THAN_512_MB":0,"LESS_THAN_1024_B":0},"objectReplicaTotalSize":0,"objectsReplicationInfo":{}}},"bucketsSizes":null} -------------------------------------------------------------------------------- /data/.minio.sys/buckets/commons/.metadata.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/data/.minio.sys/buckets/commons/.metadata.bin -------------------------------------------------------------------------------- /data/.minio.sys/buckets/commons/.usage-cache.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/data/.minio.sys/buckets/commons/.usage-cache.bin -------------------------------------------------------------------------------- /data/.minio.sys/buckets/commons/241a819241814e389548633d8402a99f.PNG/fs.json: -------------------------------------------------------------------------------- 1 | {"version":"1.0.2","checksum":{"algorithm":"","blocksize":0,"hashes":null},"meta":{"content-type":"image/png","etag":"aeb92006e503af09fe5590121758897c"}} -------------------------------------------------------------------------------- /data/.minio.sys/buckets/commons/ad94ff2e9b404772a1f9b98f4e11b4f9.PNG/fs.json: -------------------------------------------------------------------------------- 1 | {"version":"1.0.2","checksum":{"algorithm":"","blocksize":0,"hashes":null},"meta":{"content-type":"image/png","etag":"3d5606d6404bc202cd64dead0860ed50"}} -------------------------------------------------------------------------------- /data/.minio.sys/config/config.json: -------------------------------------------------------------------------------- 1 | {"api":{"_":[{"key":"requests_max","value":"0"},{"key":"requests_deadline","value":"10s"},{"key":"cluster_deadline","value":"10s"},{"key":"cors_allow_origin","value":"*"},{"key":"remote_transport_deadline","value":"2h"},{"key":"list_quorum","value":"strict"},{"key":"replication_workers","value":"250"},{"key":"replication_failed_workers","value":"8"},{"key":"transition_workers","value":"100"},{"key":"stale_uploads_cleanup_interval","value":"6h"},{"key":"stale_uploads_expiry","value":"24h"},{"key":"delete_cleanup_interval","value":"5m"}]},"audit_kafka":{"_":[{"key":"enable","value":"off"},{"key":"topic","value":""},{"key":"brokers","value":""},{"key":"sasl_username","value":""},{"key":"sasl_password","value":""},{"key":"sasl_mechanism","value":"plain"},{"key":"client_tls_cert","value":""},{"key":"client_tls_key","value":""},{"key":"tls_client_auth","value":"0"},{"key":"sasl","value":"off"},{"key":"tls","value":"off"},{"key":"tls_skip_verify","value":"off"},{"key":"version","value":""}]},"audit_webhook":{"_":[{"key":"enable","value":"off"},{"key":"endpoint","value":""},{"key":"auth_token","value":""},{"key":"client_cert","value":""},{"key":"client_key","value":""},{"key":"queue_size","value":"100000"}]},"cache":{"_":[{"key":"drives","value":""},{"key":"exclude","value":""},{"key":"expiry","value":"90"},{"key":"quota","value":"80"},{"key":"after","value":"0"},{"key":"watermark_low","value":"70"},{"key":"watermark_high","value":"80"},{"key":"range","value":"on"},{"key":"commit","value":""}]},"compression":{"_":[{"key":"enable","value":"off"},{"key":"allow_encryption","value":"off"},{"key":"extensions","value":".txt,.log,.csv,.json,.tar,.xml,.bin"},{"key":"mime_types","value":"text/*,application/json,application/xml,binary/octet-stream"}]},"credentials":{"_":[{"key":"access_key","value":"minioadmin"},{"key":"secret_key","value":"minioadmin"}]},"etcd":{"_":[{"key":"endpoints","value":""},{"key":"path_prefix","value":""},{"key":"coredns_path","value":"/skydns"},{"key":"client_cert","value":""},{"key":"client_cert_key","value":""}]},"heal":{"_":[{"key":"bitrotscan","value":"off"},{"key":"max_sleep","value":"1s"},{"key":"max_io","value":"100"}]},"identity_ldap":{"_":[{"key":"server_addr","value":""},{"key":"user_dn_search_base_dn","value":""},{"key":"user_dn_search_filter","value":""},{"key":"group_search_filter","value":""},{"key":"group_search_base_dn","value":""},{"key":"tls_skip_verify","value":"off"},{"key":"server_insecure","value":"off"},{"key":"server_starttls","value":"off"},{"key":"lookup_bind_dn","value":""},{"key":"lookup_bind_password","value":""}]},"identity_openid":{"_":[{"key":"config_url","value":""},{"key":"client_id","value":""},{"key":"client_secret","value":""},{"key":"claim_name","value":"policy"},{"key":"claim_userinfo","value":""},{"key":"role_policy","value":""},{"key":"claim_prefix","value":""},{"key":"redirect_uri","value":""},{"key":"redirect_uri_dynamic","value":"off"},{"key":"scopes","value":""}]},"identity_tls":{"_":[{"key":"skip_verify","value":"off"}]},"logger_webhook":{"_":[{"key":"enable","value":"off"},{"key":"endpoint","value":""},{"key":"auth_token","value":""},{"key":"client_cert","value":""},{"key":"client_key","value":""},{"key":"queue_size","value":"100000"}]},"notify_amqp":{"_":[{"key":"enable","value":"off"},{"key":"url","value":""},{"key":"exchange","value":""},{"key":"exchange_type","value":""},{"key":"routing_key","value":""},{"key":"mandatory","value":"off"},{"key":"durable","value":"off"},{"key":"no_wait","value":"off"},{"key":"internal","value":"off"},{"key":"auto_deleted","value":"off"},{"key":"delivery_mode","value":"0"},{"key":"publisher_confirms","value":"off"},{"key":"queue_limit","value":"0"},{"key":"queue_dir","value":""}]},"notify_elasticsearch":{"_":[{"key":"enable","value":"off"},{"key":"url","value":""},{"key":"format","value":"namespace"},{"key":"index","value":""},{"key":"queue_dir","value":""},{"key":"queue_limit","value":"0"},{"key":"username","value":""},{"key":"password","value":""}]},"notify_kafka":{"_":[{"key":"enable","value":"off"},{"key":"topic","value":""},{"key":"brokers","value":""},{"key":"sasl_username","value":""},{"key":"sasl_password","value":""},{"key":"sasl_mechanism","value":"plain"},{"key":"client_tls_cert","value":""},{"key":"client_tls_key","value":""},{"key":"tls_client_auth","value":"0"},{"key":"sasl","value":"off"},{"key":"tls","value":"off"},{"key":"tls_skip_verify","value":"off"},{"key":"queue_limit","value":"0"},{"key":"queue_dir","value":""},{"key":"version","value":""}]},"notify_mqtt":{"_":[{"key":"enable","value":"off"},{"key":"broker","value":""},{"key":"topic","value":""},{"key":"password","value":""},{"key":"username","value":""},{"key":"qos","value":"0"},{"key":"keep_alive_interval","value":"0s"},{"key":"reconnect_interval","value":"0s"},{"key":"queue_dir","value":""},{"key":"queue_limit","value":"0"}]},"notify_mysql":{"_":[{"key":"enable","value":"off"},{"key":"format","value":"namespace"},{"key":"dsn_string","value":""},{"key":"table","value":""},{"key":"queue_dir","value":""},{"key":"queue_limit","value":"0"},{"key":"max_open_connections","value":"2"}]},"notify_nats":{"_":[{"key":"enable","value":"off"},{"key":"address","value":""},{"key":"subject","value":""},{"key":"username","value":""},{"key":"password","value":""},{"key":"token","value":""},{"key":"tls","value":"off"},{"key":"tls_skip_verify","value":"off"},{"key":"cert_authority","value":""},{"key":"client_cert","value":""},{"key":"client_key","value":""},{"key":"ping_interval","value":"0"},{"key":"streaming","value":"off"},{"key":"streaming_async","value":"off"},{"key":"streaming_max_pub_acks_in_flight","value":"0"},{"key":"streaming_cluster_id","value":""},{"key":"queue_dir","value":""},{"key":"queue_limit","value":"0"}]},"notify_nsq":{"_":[{"key":"enable","value":"off"},{"key":"nsqd_address","value":""},{"key":"topic","value":""},{"key":"tls","value":"off"},{"key":"tls_skip_verify","value":"off"},{"key":"queue_dir","value":""},{"key":"queue_limit","value":"0"}]},"notify_postgres":{"_":[{"key":"enable","value":"off"},{"key":"format","value":"namespace"},{"key":"connection_string","value":""},{"key":"table","value":""},{"key":"queue_dir","value":""},{"key":"queue_limit","value":"0"},{"key":"max_open_connections","value":"2"}]},"notify_redis":{"_":[{"key":"enable","value":"off"},{"key":"format","value":"namespace"},{"key":"address","value":""},{"key":"key","value":""},{"key":"password","value":""},{"key":"queue_dir","value":""},{"key":"queue_limit","value":"0"}]},"notify_webhook":{"_":[{"key":"enable","value":"off"},{"key":"endpoint","value":""},{"key":"auth_token","value":""},{"key":"queue_limit","value":"0"},{"key":"queue_dir","value":""},{"key":"client_cert","value":""},{"key":"client_key","value":""}]},"policy_opa":{"_":[{"key":"url","value":""},{"key":"auth_token","value":""}]},"region":{"_":[{"key":"name","value":""}]},"scanner":{"_":[{"key":"delay","value":"10"},{"key":"max_wait","value":"15s"},{"key":"cycle","value":"1m"}]},"site":{"_":[{"key":"name","value":""},{"key":"region","value":""}]},"storage_class":{"_":null},"subnet":{"_":[{"key":"license","value":""},{"key":"api_key","value":""}]}} -------------------------------------------------------------------------------- /data/.minio.sys/config/iam/format.json: -------------------------------------------------------------------------------- 1 | {"version":1} -------------------------------------------------------------------------------- /data/.minio.sys/format.json: -------------------------------------------------------------------------------- 1 | {"version":"1","format":"fs","id":"dd4ce5bd-35b7-4e82-ba43-51bfd1103faf","fs":{"version":"2"}} -------------------------------------------------------------------------------- /data/commons/241a819241814e389548633d8402a99f.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/data/commons/241a819241814e389548633d8402a99f.PNG -------------------------------------------------------------------------------- /data/commons/ad94ff2e9b404772a1f9b98f4e11b4f9.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/data/commons/ad94ff2e9b404772a1f9b98f4e11b4f9.PNG -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | minio: 3 | image: minio/minio:latest 4 | container_name: minio 5 | environment: 6 | MINIO_ROOT_USER: "minioadmin" 7 | MINIO_ROOT_PASSWORD: "minioadmin" 8 | volumes: 9 | - ./data:/data 10 | ports: 11 | - 9000:9000 12 | - 9001:9001 13 | command: server /data --console-address :9001 -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /usr/local/etc/mavenrc ] ; then 40 | . /usr/local/etc/mavenrc 41 | fi 42 | 43 | if [ -f /etc/mavenrc ] ; then 44 | . /etc/mavenrc 45 | fi 46 | 47 | if [ -f "$HOME/.mavenrc" ] ; then 48 | . "$HOME/.mavenrc" 49 | fi 50 | 51 | fi 52 | 53 | # OS specific support. $var _must_ be set to either true or false. 54 | cygwin=false; 55 | darwin=false; 56 | mingw=false 57 | case "`uname`" in 58 | CYGWIN*) cygwin=true ;; 59 | MINGW*) mingw=true;; 60 | Darwin*) darwin=true 61 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 62 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 63 | if [ -z "$JAVA_HOME" ]; then 64 | if [ -x "/usr/libexec/java_home" ]; then 65 | export JAVA_HOME="`/usr/libexec/java_home`" 66 | else 67 | export JAVA_HOME="/Library/Java/Home" 68 | fi 69 | fi 70 | ;; 71 | esac 72 | 73 | if [ -z "$JAVA_HOME" ] ; then 74 | if [ -r /etc/gentoo-release ] ; then 75 | JAVA_HOME=`java-config --jre-home` 76 | fi 77 | fi 78 | 79 | if [ -z "$M2_HOME" ] ; then 80 | ## resolve links - $0 may be a link to maven's home 81 | PRG="$0" 82 | 83 | # need this for relative symlinks 84 | while [ -h "$PRG" ] ; do 85 | ls=`ls -ld "$PRG"` 86 | link=`expr "$ls" : '.*-> \(.*\)$'` 87 | if expr "$link" : '/.*' > /dev/null; then 88 | PRG="$link" 89 | else 90 | PRG="`dirname "$PRG"`/$link" 91 | fi 92 | done 93 | 94 | saveddir=`pwd` 95 | 96 | M2_HOME=`dirname "$PRG"`/.. 97 | 98 | # make it fully qualified 99 | M2_HOME=`cd "$M2_HOME" && pwd` 100 | 101 | cd "$saveddir" 102 | # echo Using m2 at $M2_HOME 103 | fi 104 | 105 | # For Cygwin, ensure paths are in UNIX format before anything is touched 106 | if $cygwin ; then 107 | [ -n "$M2_HOME" ] && 108 | M2_HOME=`cygpath --unix "$M2_HOME"` 109 | [ -n "$JAVA_HOME" ] && 110 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 111 | [ -n "$CLASSPATH" ] && 112 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 113 | fi 114 | 115 | # For Mingw, ensure paths are in UNIX format before anything is touched 116 | if $mingw ; then 117 | [ -n "$M2_HOME" ] && 118 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 119 | [ -n "$JAVA_HOME" ] && 120 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 121 | fi 122 | 123 | if [ -z "$JAVA_HOME" ]; then 124 | javaExecutable="`which javac`" 125 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 126 | # readlink(1) is not available as standard on Solaris 10. 127 | readLink=`which readlink` 128 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 129 | if $darwin ; then 130 | javaHome="`dirname \"$javaExecutable\"`" 131 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 132 | else 133 | javaExecutable="`readlink -f \"$javaExecutable\"`" 134 | fi 135 | javaHome="`dirname \"$javaExecutable\"`" 136 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 137 | JAVA_HOME="$javaHome" 138 | export JAVA_HOME 139 | fi 140 | fi 141 | fi 142 | 143 | if [ -z "$JAVACMD" ] ; then 144 | if [ -n "$JAVA_HOME" ] ; then 145 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 146 | # IBM's JDK on AIX uses strange locations for the executables 147 | JAVACMD="$JAVA_HOME/jre/sh/java" 148 | else 149 | JAVACMD="$JAVA_HOME/bin/java" 150 | fi 151 | else 152 | JAVACMD="`\\unset -f command; \\command -v java`" 153 | fi 154 | fi 155 | 156 | if [ ! -x "$JAVACMD" ] ; then 157 | echo "Error: JAVA_HOME is not defined correctly." >&2 158 | echo " We cannot execute $JAVACMD" >&2 159 | exit 1 160 | fi 161 | 162 | if [ -z "$JAVA_HOME" ] ; then 163 | echo "Warning: JAVA_HOME environment variable is not set." 164 | fi 165 | 166 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 167 | 168 | # traverses directory structure from process work directory to filesystem root 169 | # first directory with .mvn subdirectory is considered project base directory 170 | find_maven_basedir() { 171 | 172 | if [ -z "$1" ] 173 | then 174 | echo "Path not specified to find_maven_basedir" 175 | return 1 176 | fi 177 | 178 | basedir="$1" 179 | wdir="$1" 180 | while [ "$wdir" != '/' ] ; do 181 | if [ -d "$wdir"/.mvn ] ; then 182 | basedir=$wdir 183 | break 184 | fi 185 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 186 | if [ -d "${wdir}" ]; then 187 | wdir=`cd "$wdir/.."; pwd` 188 | fi 189 | # end of workaround 190 | done 191 | echo "${basedir}" 192 | } 193 | 194 | # concatenates all lines of a file 195 | concat_lines() { 196 | if [ -f "$1" ]; then 197 | echo "$(tr -s '\n' ' ' < "$1")" 198 | fi 199 | } 200 | 201 | BASE_DIR=`find_maven_basedir "$(pwd)"` 202 | if [ -z "$BASE_DIR" ]; then 203 | exit 1; 204 | fi 205 | 206 | ########################################################################################## 207 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 208 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 209 | ########################################################################################## 210 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Found .mvn/wrapper/maven-wrapper.jar" 213 | fi 214 | else 215 | if [ "$MVNW_VERBOSE" = true ]; then 216 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 217 | fi 218 | if [ -n "$MVNW_REPOURL" ]; then 219 | jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 220 | else 221 | jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 222 | fi 223 | while IFS="=" read key value; do 224 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 225 | esac 226 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 227 | if [ "$MVNW_VERBOSE" = true ]; then 228 | echo "Downloading from: $jarUrl" 229 | fi 230 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 231 | if $cygwin; then 232 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 233 | fi 234 | 235 | if command -v wget > /dev/null; then 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Found wget ... using wget" 238 | fi 239 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 240 | wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 241 | else 242 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 243 | fi 244 | elif command -v curl > /dev/null; then 245 | if [ "$MVNW_VERBOSE" = true ]; then 246 | echo "Found curl ... using curl" 247 | fi 248 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 249 | curl -o "$wrapperJarPath" "$jarUrl" -f 250 | else 251 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 252 | fi 253 | 254 | else 255 | if [ "$MVNW_VERBOSE" = true ]; then 256 | echo "Falling back to using Java to download" 257 | fi 258 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 259 | # For Cygwin, switch paths to Windows format before running javac 260 | if $cygwin; then 261 | javaClass=`cygpath --path --windows "$javaClass"` 262 | fi 263 | if [ -e "$javaClass" ]; then 264 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 265 | if [ "$MVNW_VERBOSE" = true ]; then 266 | echo " - Compiling MavenWrapperDownloader.java ..." 267 | fi 268 | # Compiling the Java class 269 | ("$JAVA_HOME/bin/javac" "$javaClass") 270 | fi 271 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 272 | # Running the downloader 273 | if [ "$MVNW_VERBOSE" = true ]; then 274 | echo " - Running MavenWrapperDownloader.java ..." 275 | fi 276 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 277 | fi 278 | fi 279 | fi 280 | fi 281 | ########################################################################################## 282 | # End of extension 283 | ########################################################################################## 284 | 285 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 286 | if [ "$MVNW_VERBOSE" = true ]; then 287 | echo $MAVEN_PROJECTBASEDIR 288 | fi 289 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 290 | 291 | # For Cygwin, switch paths to Windows format before running java 292 | if $cygwin; then 293 | [ -n "$M2_HOME" ] && 294 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 295 | [ -n "$JAVA_HOME" ] && 296 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 297 | [ -n "$CLASSPATH" ] && 298 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 299 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 300 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 301 | fi 302 | 303 | # Provide a "standardized" way to retrieve the CLI args that will 304 | # work with both Windows and non-Windows executions. 305 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 306 | export MAVEN_CMD_LINE_ARGS 307 | 308 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 309 | 310 | exec "$JAVACMD" \ 311 | $MAVEN_OPTS \ 312 | $MAVEN_DEBUG_OPTS \ 313 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 314 | "-Dmaven.home=${M2_HOME}" \ 315 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 316 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 317 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 50 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 124 | 125 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% ^ 162 | %JVM_CONFIG_MAVEN_PROPS% ^ 163 | %MAVEN_OPTS% ^ 164 | %MAVEN_DEBUG_OPTS% ^ 165 | -classpath %WRAPPER_JAR% ^ 166 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 167 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 168 | if ERRORLEVEL 1 goto error 169 | goto end 170 | 171 | :error 172 | set ERROR_CODE=1 173 | 174 | :end 175 | @endlocal & set ERROR_CODE=%ERROR_CODE% 176 | 177 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 178 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 179 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 180 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 181 | :skipRcPost 182 | 183 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 184 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 185 | 186 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 187 | 188 | cmd /C exit /B %ERROR_CODE% 189 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.6.2 9 | 10 | 11 | com.springminio 12 | app 13 | 0.0.1-SNAPSHOT 14 | app 15 | Spring Boot with Minio 16 | 17 | 11 18 | 8.2.1 19 | 5.6.5 20 | 1.9.7 21 | 3.0.0 22 | 2.9.2 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | 31 | org.projectlombok 32 | lombok 33 | true 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-test 38 | test 39 | 40 | 41 | 42 | 43 | io.minio 44 | minio 45 | ${minio.version} 46 | 47 | 48 | 49 | org.apache.commons 50 | commons-lang3 51 | 52 | 53 | 54 | cn.hutool 55 | hutool-all 56 | ${hutool.version} 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-configuration-processor 62 | true 63 | 64 | 65 | 66 | org.aspectj 67 | aspectjweaver 68 | ${aspectjweaver.version} 69 | 70 | 71 | 72 | io.springfox 73 | springfox-swagger2 74 | ${swagger2.version} 75 | 76 | 77 | 78 | io.springfox 79 | springfox-swagger-ui 80 | ${swagger.ui.version} 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | org.springframework.boot 89 | spring-boot-maven-plugin 90 | 91 | 92 | 93 | org.projectlombok 94 | lombok 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /screenshots/screenshot_1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/screenshots/screenshot_1.PNG -------------------------------------------------------------------------------- /screenshots/screenshot_10.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/screenshots/screenshot_10.PNG -------------------------------------------------------------------------------- /screenshots/screenshot_11.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/screenshots/screenshot_11.PNG -------------------------------------------------------------------------------- /screenshots/screenshot_12.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/screenshots/screenshot_12.PNG -------------------------------------------------------------------------------- /screenshots/screenshot_13.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/screenshots/screenshot_13.PNG -------------------------------------------------------------------------------- /screenshots/screenshot_14.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/screenshots/screenshot_14.PNG -------------------------------------------------------------------------------- /screenshots/screenshot_15.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/screenshots/screenshot_15.PNG -------------------------------------------------------------------------------- /screenshots/screenshot_16.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/screenshots/screenshot_16.PNG -------------------------------------------------------------------------------- /screenshots/screenshot_17.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/screenshots/screenshot_17.PNG -------------------------------------------------------------------------------- /screenshots/screenshot_18.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/screenshots/screenshot_18.PNG -------------------------------------------------------------------------------- /screenshots/screenshot_19.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/screenshots/screenshot_19.PNG -------------------------------------------------------------------------------- /screenshots/screenshot_2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/screenshots/screenshot_2.PNG -------------------------------------------------------------------------------- /screenshots/screenshot_20.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/screenshots/screenshot_20.PNG -------------------------------------------------------------------------------- /screenshots/screenshot_3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/screenshots/screenshot_3.PNG -------------------------------------------------------------------------------- /screenshots/screenshot_4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/screenshots/screenshot_4.PNG -------------------------------------------------------------------------------- /screenshots/screenshot_5.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/screenshots/screenshot_5.PNG -------------------------------------------------------------------------------- /screenshots/screenshot_6.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/screenshots/screenshot_6.PNG -------------------------------------------------------------------------------- /screenshots/screenshot_7.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/screenshots/screenshot_7.PNG -------------------------------------------------------------------------------- /screenshots/screenshot_8.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/screenshots/screenshot_8.PNG -------------------------------------------------------------------------------- /screenshots/screenshot_9.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/screenshots/screenshot_9.PNG -------------------------------------------------------------------------------- /screenshots/springboot_minio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rapter1990/SpringBootMinio/c030ae0c02073f35d1002557a225f371fdf21e68/screenshots/springboot_minio.png -------------------------------------------------------------------------------- /src/main/java/com/springminio/app/AppApplication.java: -------------------------------------------------------------------------------- 1 | package com.springminio.app; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 6 | 7 | @SpringBootApplication 8 | @EnableSwagger2 9 | public class AppApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(AppApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/springminio/app/aop/MinioServiceImplAspect.java: -------------------------------------------------------------------------------- 1 | package com.springminio.app.aop; 2 | 3 | import org.aspectj.lang.JoinPoint; 4 | import org.aspectj.lang.annotation.After; 5 | import org.aspectj.lang.annotation.AfterReturning; 6 | import org.aspectj.lang.annotation.Aspect; 7 | import org.aspectj.lang.annotation.Before; 8 | import org.springframework.stereotype.Component; 9 | 10 | @Aspect 11 | @Component 12 | public class MinioServiceImplAspect { 13 | 14 | @Before(value="execution(* com.springminio.app.service.MinioService.*(..))") 15 | public void beforeAdvice(JoinPoint joinPoint){ 16 | System.out.println("MinioServiceImplAspect | Before MinioService method got called"); 17 | } 18 | 19 | @After(value="execution(* com.springminio.app.service.MinioService.*(..))") 20 | public void afterAdvice(JoinPoint joinPoint){ 21 | System.out.println("MinioServiceImplAspect | After MinioService method got called"); 22 | } 23 | 24 | @AfterReturning(value="execution(* com.springminio.app.service.MinioService.*(..))") 25 | public void afterReturningAdvice(JoinPoint joinPoint){ 26 | System.out.println("MinioServiceImplAspect | AfterReturning MinioService method got called"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/springminio/app/config/MinioConfig.java: -------------------------------------------------------------------------------- 1 | package com.springminio.app.config; 2 | 3 | import io.minio.MinioClient; 4 | import lombok.Data; 5 | import org.springframework.boot.context.properties.ConfigurationProperties; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | @Data 10 | @Configuration 11 | @ConfigurationProperties(prefix = "minio") 12 | public class MinioConfig { 13 | 14 | /** * It's a URL, domain name ,IPv4 perhaps IPv6 Address ") */ 15 | private String endpoint; 16 | 17 | /** * //"TCP/IP Port number " */ 18 | private Integer port; 19 | 20 | /** * //"accessKey Similar to user ID, Used to uniquely identify your account " */ 21 | private String accessKey; 22 | 23 | /** * //"secretKey It's the password for your account " */ 24 | private String secretKey; 25 | 26 | /** * //" If it is true, It uses https instead of http, The default value is true" */ 27 | private boolean secure; 28 | 29 | /** * //" Default bucket " */ 30 | private String bucketName; 31 | 32 | /** * The maximum size of the picture */ 33 | private long imageSize; 34 | 35 | /** * Maximum size of other files */ 36 | private long fileSize; 37 | 38 | @Bean 39 | public MinioClient minioClient() { 40 | MinioClient minioClient = 41 | MinioClient.builder() 42 | .credentials(accessKey, secretKey) 43 | .endpoint(endpoint,port,secure) 44 | .build(); 45 | return minioClient; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/springminio/app/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.springminio.app.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 6 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; 7 | import springfox.documentation.builders.ApiInfoBuilder; 8 | import springfox.documentation.builders.PathSelectors; 9 | import springfox.documentation.builders.RequestHandlerSelectors; 10 | import springfox.documentation.service.ApiInfo; 11 | import springfox.documentation.service.Contact; 12 | import springfox.documentation.spi.DocumentationType; 13 | import springfox.documentation.spring.web.plugins.Docket; 14 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 15 | 16 | @Configuration 17 | @EnableSwagger2 18 | public class SwaggerConfig extends WebMvcConfigurationSupport { 19 | 20 | @Bean 21 | public Docket api() { 22 | return new Docket(DocumentationType.SWAGGER_2).select() 23 | .apis(RequestHandlerSelectors.basePackage("com.springminio")) 24 | .paths(PathSelectors.regex("/.*")) 25 | .build().apiInfo(apiEndPointsInfo()); 26 | 27 | } 28 | 29 | private ApiInfo apiEndPointsInfo() { 30 | return new ApiInfoBuilder().title("Spring Boot Minio") 31 | .description("The usage of Minio in Spring Boot App") 32 | .contact(new Contact("Noyan Germiyanoğlu", "github.com/Rapter1990", "sngermiyanoglu@hotmail.com")) 33 | .license("Apache 2.0") 34 | .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html") 35 | .version("1.12.3") 36 | .build(); 37 | } 38 | 39 | @Override 40 | protected void addResourceHandlers(ResourceHandlerRegistry registry) { 41 | registry.addResourceHandler("swagger-ui.html") 42 | .addResourceLocations("classpath:/META-INF/resources/"); 43 | 44 | registry.addResourceHandler("/webjars/**") 45 | .addResourceLocations("classpath:/META-INF/resources/webjars/"); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/springminio/app/controller/MinioController.java: -------------------------------------------------------------------------------- 1 | package com.springminio.app.controller; 2 | 3 | import com.springminio.app.exception.FileResponseException; 4 | import com.springminio.app.payload.FileResponse; 5 | import com.springminio.app.service.MinioService; 6 | import com.springminio.app.util.FileTypeUtils; 7 | import lombok.RequiredArgsConstructor; 8 | import org.apache.tomcat.util.http.fileupload.IOUtils; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | import org.springframework.beans.factory.annotation.Value; 12 | import org.springframework.web.bind.annotation.*; 13 | import org.springframework.web.multipart.MultipartFile; 14 | 15 | import javax.servlet.http.HttpServletResponse; 16 | import java.io.IOException; 17 | import java.io.InputStream; 18 | import java.io.UnsupportedEncodingException; 19 | import java.net.URLEncoder; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | @RestController 25 | @RequiredArgsConstructor 26 | @RequestMapping("/minio") 27 | public class MinioController { 28 | 29 | private static final Logger LOGGER = LoggerFactory.getLogger(MinioController.class); 30 | 31 | private final MinioService minioService; 32 | 33 | @Value("${server.port}") 34 | private int portNumber; 35 | 36 | @PostMapping("/upload") 37 | public FileResponse uploadFile(MultipartFile file, String bucketName) { 38 | 39 | LOGGER.info("MinioController | uploadFile is called"); 40 | 41 | LOGGER.info("MinioController | uploadFile | bucketName : " + bucketName); 42 | 43 | String fileType = FileTypeUtils.getFileType(file); 44 | 45 | LOGGER.info("MinioController | uploadFile | fileType : " + fileType); 46 | 47 | if (fileType != null) { 48 | return minioService.putObject(file, bucketName, fileType); 49 | } 50 | throw new FileResponseException("File cannot be Upload"); 51 | } 52 | 53 | @PostMapping("/addBucket/{bucketName}") 54 | public String addBucket(@PathVariable String bucketName) { 55 | 56 | LOGGER.info("MinioController | addBucket is called"); 57 | 58 | LOGGER.info("MinioController | addBucket | bucketName : " + bucketName); 59 | 60 | minioService.makeBucket(bucketName); 61 | return "Bucket name "+ bucketName +" created"; 62 | } 63 | 64 | @GetMapping("/show/{bucketName}") 65 | public List show(@PathVariable String bucketName) { 66 | 67 | LOGGER.info("MinioController | show is called"); 68 | 69 | LOGGER.info("MinioController | show | bucketName : " + bucketName); 70 | 71 | return minioService.listObjectNames(bucketName); 72 | } 73 | 74 | @GetMapping("/showBucketName") 75 | public List showBucketName() { 76 | 77 | LOGGER.info("MinioController | showBucketName is called"); 78 | 79 | return minioService.listBucketName(); 80 | } 81 | 82 | @DeleteMapping("/removeBucket/{bucketName}") 83 | public String delBucketName(@PathVariable String bucketName) { 84 | 85 | LOGGER.info("MinioController | delBucketName is called"); 86 | 87 | LOGGER.info("MinioController | delBucketName | bucketName : " + bucketName); 88 | 89 | boolean state = minioService.removeBucket(bucketName); 90 | 91 | LOGGER.info("MinioController | delBucketName | state : " + state); 92 | 93 | if(state){ 94 | return " Delete Bucket Name successfully "; 95 | }else{ 96 | return " Delete failed "; 97 | } 98 | } 99 | 100 | @DeleteMapping("/removeObject/{bucketName}/{objectName}") 101 | public String delObject(@PathVariable("bucketName") String bucketName, @PathVariable("objectName") String objectName) { 102 | 103 | LOGGER.info("MinioController | delObject is called"); 104 | 105 | LOGGER.info("MinioController | delObject | bucketName : " + bucketName); 106 | LOGGER.info("MinioController | delObject | objectName : " + objectName); 107 | 108 | boolean state = minioService.removeObject(bucketName, objectName); 109 | 110 | LOGGER.info("MinioController | delBucketName | state : " + state); 111 | 112 | if(state){ 113 | return " Delete Object successfully "; 114 | }else { 115 | return " Delete failed "; 116 | } 117 | } 118 | 119 | @DeleteMapping("/removeListObject/{bucketName}") 120 | public String delListObject(@PathVariable("bucketName") String bucketName, @RequestBody List objectNameList) { 121 | 122 | LOGGER.info("MinioController | delListObject is called"); 123 | 124 | LOGGER.info("MinioController | delListObject | bucketName : " + bucketName); 125 | LOGGER.info("MinioController | delListObject | objectNameList size : " + objectNameList.size()); 126 | 127 | boolean state = minioService.removeListObject(bucketName, objectNameList) ; 128 | 129 | LOGGER.info("MinioController | delBucketName | state : " + state); 130 | 131 | if(state){ 132 | return " Delete List Object successfully "; 133 | }else { 134 | return " Delete failed "; 135 | } 136 | } 137 | 138 | @GetMapping("/showListObjectNameAndDownloadUrl/{bucketName}") 139 | public Map showListObjectNameAndDownloadUrl(@PathVariable String bucketName) { 140 | 141 | LOGGER.info("MinioController | showListObjectNameAndDownloadUrl is called"); 142 | 143 | LOGGER.info("MinioController | showListObjectNameAndDownloadUrl | bucketName : " + bucketName); 144 | 145 | Map map = new HashMap<>(); 146 | List listObjectNames = minioService.listObjectNames(bucketName); 147 | 148 | LOGGER.info("MinioController | showListObjectNameAndDownloadUrl | listObjectNames size : " + listObjectNames.size()); 149 | 150 | String url = "localhost:" + portNumber + "/minio/download/" + bucketName + "/"; 151 | LOGGER.info("MinioController | showListObjectNameAndDownloadUrl | url : " + url); 152 | 153 | for (int i = 0; i errorDetails; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/springminio/app/exception/FileResponseException.java: -------------------------------------------------------------------------------- 1 | package com.springminio.app.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.ResponseStatus; 5 | 6 | @ResponseStatus(HttpStatus.NOT_FOUND) 7 | public class FileResponseException extends RuntimeException { 8 | 9 | public FileResponseException(String msg) { 10 | super(msg); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/springminio/app/exception/error/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.springminio.app.exception.error; 2 | 3 | import com.springminio.app.exception.ApiError; 4 | import com.springminio.app.exception.FileResponseException; 5 | import org.springframework.http.HttpHeaders; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.http.converter.HttpMessageNotReadableException; 9 | import org.springframework.web.HttpMediaTypeNotSupportedException; 10 | import org.springframework.web.bind.MethodArgumentNotValidException; 11 | import org.springframework.web.bind.MissingServletRequestParameterException; 12 | import org.springframework.web.bind.annotation.ControllerAdvice; 13 | import org.springframework.web.bind.annotation.ExceptionHandler; 14 | import org.springframework.web.context.request.WebRequest; 15 | import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; 16 | 17 | import java.time.LocalDateTime; 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import java.util.stream.Collectors; 21 | 22 | @ControllerAdvice 23 | public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { 24 | 25 | // handleHttpMediaTypeNotSupported : triggers when the JSON is invalid 26 | @Override 27 | protected ResponseEntity handleHttpMediaTypeNotSupported( 28 | HttpMediaTypeNotSupportedException ex, 29 | HttpHeaders headers, 30 | HttpStatus status, 31 | WebRequest request) { 32 | 33 | List details = new ArrayList(); 34 | 35 | 36 | StringBuilder builder = new StringBuilder(); 37 | builder.append(ex.getContentType()); 38 | builder.append(" media type is not supported. Supported media types are "); 39 | ex.getSupportedMediaTypes().forEach(t -> builder.append(t).append(", ")); 40 | 41 | details.add(builder.toString()); 42 | 43 | ApiError err = new ApiError(HttpStatus.BAD_REQUEST.value(), HttpStatus.BAD_REQUEST, LocalDateTime.now() , 44 | "Invalid JSON", details); 45 | 46 | return ResponseEntity.status(status).body(err); 47 | 48 | } 49 | 50 | // handleHttpMessageNotReadable : triggers when the JSON is malformed 51 | @Override 52 | protected ResponseEntity handleHttpMessageNotReadable(HttpMessageNotReadableException ex, 53 | HttpHeaders headers, HttpStatus status, 54 | WebRequest request) { 55 | 56 | List details = new ArrayList(); 57 | details.add(ex.getMessage()); 58 | 59 | ApiError err = new ApiError(HttpStatus.BAD_REQUEST.value(), HttpStatus.BAD_REQUEST, LocalDateTime.now() , 60 | "Malformed JSON request", details); 61 | 62 | 63 | return ResponseEntity.status(status).body(err); 64 | } 65 | 66 | // handleMethodArgumentNotValid : triggers when @Valid fails 67 | @Override 68 | protected ResponseEntity handleMethodArgumentNotValid(MethodArgumentNotValidException ex, 69 | HttpHeaders headers, HttpStatus status, 70 | WebRequest request) { 71 | 72 | List details = new ArrayList(); 73 | details = ex.getBindingResult() 74 | .getFieldErrors() 75 | .stream() 76 | .map(error -> error.getObjectName() + " : " + error.getDefaultMessage()) 77 | .collect(Collectors.toList()); 78 | 79 | 80 | ApiError err = new ApiError(HttpStatus.BAD_REQUEST.value(), HttpStatus.BAD_REQUEST, LocalDateTime.now() , 81 | "Validation Errors", details); 82 | 83 | return ResponseEntity.status(status).body(err); 84 | } 85 | 86 | // handleMissingServletRequestParameter : triggers when there are missing parameters 87 | @Override 88 | protected ResponseEntity handleMissingServletRequestParameter( 89 | MissingServletRequestParameterException ex, HttpHeaders headers, 90 | HttpStatus status, WebRequest request) { 91 | 92 | List details = new ArrayList(); 93 | details.add(ex.getParameterName() + " parameter is missing"); 94 | 95 | ApiError err = new ApiError(HttpStatus.BAD_REQUEST.value(), HttpStatus.BAD_REQUEST, LocalDateTime.now() , 96 | "Missing Parameters", details); 97 | 98 | return ResponseEntity.status(status).body(err); 99 | } 100 | 101 | // handleCategoryNotFoundException : triggers when there is not resource with the specified ID in Category 102 | @ExceptionHandler(FileResponseException.class) 103 | public ResponseEntity handleFileResponseNotFoundException(FileResponseException ex) { 104 | 105 | List details = new ArrayList(); 106 | details.add(ex.getMessage()); 107 | 108 | ApiError err = new ApiError(HttpStatus.BAD_REQUEST.value(), HttpStatus.BAD_REQUEST, LocalDateTime.now() , 109 | "FileResponseException", details); 110 | 111 | return ResponseEntity.status(HttpStatus.NOT_FOUND).body(err); 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/com/springminio/app/payload/FileResponse.java: -------------------------------------------------------------------------------- 1 | package com.springminio.app.payload; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.*; 5 | import java.time.LocalDateTime; 6 | 7 | @Data 8 | @NoArgsConstructor 9 | @AllArgsConstructor 10 | @EqualsAndHashCode 11 | @Builder 12 | public class FileResponse { 13 | String filename; 14 | String contentType; 15 | Long fileSize; 16 | 17 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'", timezone = "GMT") 18 | private LocalDateTime createdTime; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/springminio/app/service/MinioService.java: -------------------------------------------------------------------------------- 1 | package com.springminio.app.service; 2 | 3 | import com.springminio.app.payload.FileResponse; 4 | import io.minio.messages.Bucket; 5 | import org.springframework.web.multipart.MultipartFile; 6 | 7 | import java.io.InputStream; 8 | import java.util.List; 9 | 10 | public interface MinioService { 11 | 12 | //Check Whether bucket already exists 13 | boolean bucketExists(String bucketName); 14 | 15 | // Create a bucket 16 | void makeBucket(String bucketName); 17 | 18 | // List all bucket names 19 | List listBucketName(); 20 | 21 | //List all buckets 22 | List listBuckets(); 23 | 24 | // Delete Bucket by Name 25 | boolean removeBucket(String bucketName); 26 | 27 | // List all object names in the bucket 28 | List listObjectNames(String bucketName); 29 | 30 | // Upload files in the bucket 31 | FileResponse putObject(MultipartFile multipartFile, String bucketName, String fileType); 32 | 33 | // Download file from bucket 34 | InputStream downloadObject(String bucketName, String objectName); 35 | 36 | // Delete file in bucket 37 | boolean removeObject(String bucketName, String objectName); 38 | 39 | // Delete files in bucket 40 | boolean removeListObject(String bucketName, List objectNameList); 41 | 42 | // Get file path from bucket 43 | String getObjectUrl(String bucketName,String objectName); 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/springminio/app/service/impl/MinioServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.springminio.app.service.impl; 2 | 3 | import com.springminio.app.config.MinioConfig; 4 | import com.springminio.app.payload.FileResponse; 5 | import com.springminio.app.service.MinioService; 6 | import com.springminio.app.util.MinioUtil; 7 | import io.minio.messages.Bucket; 8 | import lombok.RequiredArgsConstructor; 9 | import lombok.SneakyThrows; 10 | import org.apache.commons.lang3.StringUtils; 11 | import org.slf4j.Logger; 12 | import org.slf4j.LoggerFactory; 13 | import org.springframework.stereotype.Service; 14 | import org.springframework.web.multipart.MultipartFile; 15 | 16 | import java.io.InputStream; 17 | import java.time.LocalDateTime; 18 | import java.util.List; 19 | import java.util.UUID; 20 | 21 | @Service 22 | @RequiredArgsConstructor 23 | public class MinioServiceImpl implements MinioService { 24 | 25 | private static final Logger LOGGER = LoggerFactory.getLogger(MinioServiceImpl.class); 26 | 27 | private final MinioUtil minioUtil; 28 | private final MinioConfig minioProperties; 29 | 30 | 31 | @Override 32 | public boolean bucketExists(String bucketName) { 33 | LOGGER.info("MinioServiceImpl | bucketExists is called"); 34 | 35 | return minioUtil.bucketExists(bucketName); 36 | } 37 | 38 | @Override 39 | public void makeBucket(String bucketName) { 40 | LOGGER.info("MinioServiceImpl | makeBucket is called"); 41 | 42 | LOGGER.info("MinioServiceImpl | makeBucket | bucketName : " + bucketName); 43 | 44 | minioUtil.makeBucket(bucketName); 45 | } 46 | 47 | @Override 48 | public List listBucketName() { 49 | LOGGER.info("MinioServiceImpl | listBucketName is called"); 50 | return minioUtil.listBucketNames(); 51 | } 52 | 53 | @Override 54 | public List listBuckets() { 55 | LOGGER.info("MinioServiceImpl | listBuckets is called"); 56 | return minioUtil.listBuckets(); 57 | } 58 | 59 | @Override 60 | public boolean removeBucket(String bucketName) { 61 | LOGGER.info("MinioServiceImpl | removeBucket is called"); 62 | 63 | LOGGER.info("MinioServiceImpl | removeBucket | bucketName : " + bucketName); 64 | 65 | return minioUtil.removeBucket(bucketName); 66 | } 67 | 68 | @Override 69 | public List listObjectNames(String bucketName) { 70 | LOGGER.info("MinioServiceImpl | listObjectNames is called"); 71 | 72 | LOGGER.info("MinioServiceImpl | listObjectNames | bucketName : " + bucketName); 73 | 74 | return minioUtil.listObjectNames(bucketName); 75 | } 76 | 77 | @SneakyThrows 78 | @Override 79 | public FileResponse putObject(MultipartFile multipartFile, String bucketName, String fileType) { 80 | 81 | LOGGER.info("MinioServiceImpl | putObject is called"); 82 | 83 | try { 84 | bucketName = StringUtils.isNotBlank(bucketName) ? bucketName : minioProperties.getBucketName(); 85 | 86 | LOGGER.info("MinioServiceImpl | putObject | bucketName : " + bucketName); 87 | 88 | if (!this.bucketExists(bucketName)) { 89 | this.makeBucket(bucketName); 90 | LOGGER.info("MinioServiceImpl | putObject | bucketName : " + bucketName + " created"); 91 | } 92 | 93 | String fileName = multipartFile.getOriginalFilename(); 94 | LOGGER.info("MinioServiceImpl | getFileType | fileName : " + fileName); 95 | 96 | Long fileSize = multipartFile.getSize(); 97 | LOGGER.info("MinioServiceImpl | getFileType | fileSize : " + fileSize); 98 | 99 | String objectName = UUID.randomUUID().toString().replaceAll("-", "") 100 | + fileName.substring(fileName.lastIndexOf(".")); 101 | LOGGER.info("MinioServiceImpl | getFileType | objectName : " + objectName); 102 | 103 | LocalDateTime createdTime = LocalDateTime.now(); 104 | LOGGER.info("MinioServiceImpl | getFileType | createdTime : " + createdTime); 105 | 106 | minioUtil.putObject(bucketName, multipartFile, objectName,fileType); 107 | 108 | LOGGER.info("MinioServiceImpl | getFileType | url : " + minioProperties.getEndpoint()+"/"+bucketName+"/"+objectName); 109 | 110 | return FileResponse.builder() 111 | .filename(objectName) 112 | .fileSize(fileSize) 113 | .contentType(fileType) 114 | .createdTime(createdTime) 115 | .build(); 116 | 117 | } catch (Exception e) { 118 | LOGGER.info("MinioServiceImpl | getFileType | Exception : " + e.getMessage()); 119 | return null; 120 | } 121 | } 122 | 123 | @Override 124 | public InputStream downloadObject(String bucketName, String objectName) { 125 | LOGGER.info("MinioServiceImpl | downloadObject is called"); 126 | 127 | LOGGER.info("MinioServiceImpl | downloadObject | bucketName : " + bucketName); 128 | LOGGER.info("MinioServiceImpl | downloadObject | objectName : " + objectName); 129 | 130 | return minioUtil.getObject(bucketName,objectName); 131 | } 132 | 133 | @Override 134 | public boolean removeObject(String bucketName, String objectName) { 135 | LOGGER.info("MinioServiceImpl | removeObject is called"); 136 | 137 | LOGGER.info("MinioServiceImpl | removeObject | bucketName : " + bucketName); 138 | LOGGER.info("MinioServiceImpl | removeObject | objectName : " + objectName); 139 | 140 | return minioUtil.removeObject(bucketName, objectName); 141 | } 142 | 143 | @Override 144 | public boolean removeListObject(String bucketName, List objectNameList) { 145 | LOGGER.info("MinioServiceImpl | removeListObject is called"); 146 | 147 | LOGGER.info("MinioServiceImpl | removeObject | bucketName : " + bucketName); 148 | LOGGER.info("MinioServiceImpl | removeObject | objectNameList size : " + objectNameList.size()); 149 | 150 | return minioUtil.removeObject(bucketName,objectNameList); 151 | } 152 | 153 | @Override 154 | public String getObjectUrl(String bucketName, String objectName) { 155 | LOGGER.info("MinioServiceImpl | getObjectUrl is called"); 156 | 157 | LOGGER.info("MinioServiceImpl | getObjectUrl | bucketName : " + bucketName); 158 | LOGGER.info("MinioServiceImpl | getObjectUrl | objectName : " + objectName); 159 | 160 | return minioUtil.getObjectUrl(bucketName, objectName); 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /src/main/java/com/springminio/app/util/FileTypeUtils.java: -------------------------------------------------------------------------------- 1 | package com.springminio.app.util; 2 | 3 | import cn.hutool.core.io.FileTypeUtil; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.web.multipart.MultipartFile; 7 | 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | 11 | 12 | public class FileTypeUtils { 13 | 14 | private static final Logger LOGGER = LoggerFactory.getLogger(FileTypeUtils.class); 15 | 16 | private final static String IMAGE_TYPE = "image/"; 17 | private final static String AUDIO_TYPE = "audio/"; 18 | private final static String VIDEO_TYPE = "video/"; 19 | private final static String APPLICATION_TYPE = "application/"; 20 | private final static String TXT_TYPE = "text/"; 21 | 22 | public static String getFileType(MultipartFile multipartFile) { 23 | 24 | InputStream inputStream = null; 25 | String type = null; 26 | 27 | try { 28 | inputStream = multipartFile.getInputStream(); 29 | type = FileTypeUtil.getType(inputStream); 30 | LOGGER.info("FileTypeUtils | getFileType | type : " + type); 31 | 32 | if (type.equalsIgnoreCase("JPG") || type.equalsIgnoreCase("JPEG") 33 | || type.equalsIgnoreCase("GIF") || type.equalsIgnoreCase("PNG") 34 | || type.equalsIgnoreCase("BMP") || type.equalsIgnoreCase("PCX") 35 | || type.equalsIgnoreCase("TGA") || type.equalsIgnoreCase("PSD") 36 | || type.equalsIgnoreCase("TIFF")) { 37 | 38 | LOGGER.info("FileTypeUtils | getFileType | IMAGE_TYPE+type : " + IMAGE_TYPE+type); 39 | return IMAGE_TYPE+type; 40 | } 41 | 42 | if (type.equalsIgnoreCase("mp3") || type.equalsIgnoreCase("OGG") 43 | || type.equalsIgnoreCase("WAV") || type.equalsIgnoreCase("REAL") 44 | || type.equalsIgnoreCase("APE") || type.equalsIgnoreCase("MODULE") 45 | || type.equalsIgnoreCase("MIDI") || type.equalsIgnoreCase("VQF") 46 | || type.equalsIgnoreCase("CD")) { 47 | 48 | LOGGER.info("FileTypeUtils | getFileType | AUDIO_TYPE+type : " + AUDIO_TYPE+type); 49 | return AUDIO_TYPE+type; 50 | } 51 | if (type.equalsIgnoreCase("mp4") || type.equalsIgnoreCase("avi") 52 | || type.equalsIgnoreCase("MPEG-1") || type.equalsIgnoreCase("RM") 53 | || type.equalsIgnoreCase("ASF") || type.equalsIgnoreCase("WMV") 54 | || type.equalsIgnoreCase("qlv") || type.equalsIgnoreCase("MPEG-2") 55 | || type.equalsIgnoreCase("MPEG4") || type.equalsIgnoreCase("mov") 56 | || type.equalsIgnoreCase("3gp")) { 57 | 58 | LOGGER.info("FileTypeUtils | getFileType | VIDEO_TYPE+type : " + VIDEO_TYPE+type); 59 | return VIDEO_TYPE+type; 60 | } 61 | if (type.equalsIgnoreCase("doc") || type.equalsIgnoreCase("docx") 62 | || type.equalsIgnoreCase("ppt") || type.equalsIgnoreCase("pptx") 63 | || type.equalsIgnoreCase("xls") || type.equalsIgnoreCase("xlsx") 64 | || type.equalsIgnoreCase("zip")||type.equalsIgnoreCase("jar")) { 65 | 66 | LOGGER.info("FileTypeUtils | getFileType | APPLICATION_TYPE+type : " + APPLICATION_TYPE+type); 67 | return APPLICATION_TYPE+type; 68 | } 69 | if (type.equalsIgnoreCase("txt")) { 70 | 71 | LOGGER.info("FileTypeUtils | getFileType | TXT_TYPE+type : " + TXT_TYPE+type); 72 | return TXT_TYPE+type; 73 | } 74 | 75 | }catch (IOException e){ 76 | LOGGER.info("FileTypeUtils | getFileType | IOException : " + e.getMessage()); 77 | } 78 | 79 | return null; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/springminio/app/util/MinioUtil.java: -------------------------------------------------------------------------------- 1 | package com.springminio.app.util; 2 | 3 | import com.springminio.app.config.MinioConfig; 4 | import io.minio.*; 5 | import io.minio.http.Method; 6 | import io.minio.messages.Bucket; 7 | import io.minio.messages.DeleteError; 8 | import io.minio.messages.DeleteObject; 9 | import io.minio.messages.Item; 10 | import lombok.RequiredArgsConstructor; 11 | import lombok.SneakyThrows; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | import org.springframework.stereotype.Component; 15 | import org.springframework.web.multipart.MultipartFile; 16 | 17 | import java.io.ByteArrayInputStream; 18 | import java.io.InputStream; 19 | import java.util.ArrayList; 20 | import java.util.LinkedList; 21 | import java.util.List; 22 | import java.util.concurrent.TimeUnit; 23 | 24 | @Component 25 | @RequiredArgsConstructor 26 | public class MinioUtil { 27 | 28 | private static final Logger LOGGER = LoggerFactory.getLogger(MinioUtil.class); 29 | 30 | private final MinioClient minioClient; 31 | private final MinioConfig minioConfig; 32 | 33 | // Upload Files 34 | @SneakyThrows 35 | public void putObject(String bucketName, MultipartFile multipartFile, String filename, String fileType) { 36 | 37 | LOGGER.info("MinioUtil | putObject is called"); 38 | 39 | LOGGER.info("MinioUtil | putObject | filename : " + filename); 40 | LOGGER.info("MinioUtil | putObject | fileType : " + fileType); 41 | 42 | InputStream inputStream = new ByteArrayInputStream(multipartFile.getBytes()); 43 | 44 | minioClient.putObject( 45 | PutObjectArgs.builder().bucket(bucketName).object(filename).stream( 46 | inputStream, -1, minioConfig.getFileSize()) 47 | .contentType(fileType) 48 | .build()); 49 | } 50 | 51 | // Check if bucket name exists 52 | @SneakyThrows 53 | public boolean bucketExists(String bucketName) { 54 | 55 | LOGGER.info("MinioUtil | bucketExists is called"); 56 | 57 | boolean found = 58 | minioClient.bucketExists( 59 | BucketExistsArgs.builder(). 60 | bucket(bucketName). 61 | build()); 62 | 63 | LOGGER.info("MinioUtil | bucketExists | found : " + found); 64 | 65 | if (found) { 66 | LOGGER.info("MinioUtil | bucketExists | message : " + bucketName + " exists"); 67 | } else { 68 | LOGGER.info("MinioUtil | bucketExists | message : " + bucketName + " does not exist"); 69 | } 70 | return found; 71 | } 72 | 73 | // Create bucket name 74 | @SneakyThrows 75 | public boolean makeBucket(String bucketName) { 76 | 77 | LOGGER.info("MinioUtil | makeBucket is called"); 78 | 79 | boolean flag = bucketExists(bucketName); 80 | 81 | LOGGER.info("MinioUtil | makeBucket | flag : " + flag); 82 | 83 | if (!flag) { 84 | minioClient.makeBucket( 85 | MakeBucketArgs.builder() 86 | .bucket(bucketName) 87 | .build()); 88 | 89 | return true; 90 | } else { 91 | return false; 92 | } 93 | } 94 | 95 | // List all buckets 96 | @SneakyThrows 97 | public List listBuckets() { 98 | LOGGER.info("MinioUtil | listBuckets is called"); 99 | 100 | return minioClient.listBuckets(); 101 | } 102 | 103 | // List all bucket names 104 | @SneakyThrows 105 | public List listBucketNames() { 106 | 107 | LOGGER.info("MinioUtil | listBucketNames is called"); 108 | 109 | List bucketList = listBuckets(); 110 | 111 | LOGGER.info("MinioUtil | listBucketNames | bucketList size : " + bucketList.size()); 112 | 113 | List bucketListName = new ArrayList<>(); 114 | for (Bucket bucket : bucketList) { 115 | bucketListName.add(bucket.name()); 116 | } 117 | 118 | LOGGER.info("MinioUtil | listBucketNames | bucketListName size : " + bucketListName.size()); 119 | 120 | return bucketListName; 121 | } 122 | 123 | // List all objects from the specified bucket 124 | @SneakyThrows 125 | public Iterable> listObjects(String bucketName) { 126 | 127 | LOGGER.info("MinioUtil | listObjects is called"); 128 | 129 | boolean flag = bucketExists(bucketName); 130 | 131 | LOGGER.info("MinioUtil | listObjects | flag : " + flag); 132 | 133 | if (flag) { 134 | return minioClient.listObjects( 135 | ListObjectsArgs.builder().bucket(bucketName).build()); 136 | } 137 | return null; 138 | } 139 | 140 | // Delete Bucket by its name from the specified bucket 141 | @SneakyThrows 142 | public boolean removeBucket(String bucketName) { 143 | 144 | LOGGER.info("MinioUtil | removeBucket is called"); 145 | 146 | boolean flag = bucketExists(bucketName); 147 | LOGGER.info("MinioUtil | removeBucket | flag : " + flag); 148 | 149 | if (flag) { 150 | Iterable> myObjects = listObjects(bucketName); 151 | 152 | for (Result result : myObjects) { 153 | Item item = result.get(); 154 | // Delete failed when There are object files in bucket 155 | 156 | LOGGER.info("MinioUtil | removeBucket | item size : " + item.size()); 157 | 158 | if (item.size() > 0) { 159 | return false; 160 | } 161 | } 162 | 163 | // Delete bucket when bucket is empty 164 | minioClient.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build()); 165 | flag = bucketExists(bucketName); 166 | 167 | LOGGER.info("MinioUtil | removeBucket | flag : " + flag); 168 | if (!flag) { 169 | return true; 170 | } 171 | } 172 | return false; 173 | } 174 | 175 | // List all object names from the specified bucket 176 | @SneakyThrows 177 | public List listObjectNames(String bucketName) { 178 | 179 | LOGGER.info("MinioUtil | listObjectNames is called"); 180 | 181 | List listObjectNames = new ArrayList<>(); 182 | boolean flag = bucketExists(bucketName); 183 | 184 | LOGGER.info("MinioUtil | listObjectNames | flag : " + flag); 185 | 186 | if (flag) { 187 | Iterable> myObjects = listObjects(bucketName); 188 | for (Result result : myObjects) { 189 | Item item = result.get(); 190 | listObjectNames.add(item.objectName()); 191 | } 192 | } else { 193 | listObjectNames.add(" Bucket does not exist "); 194 | } 195 | 196 | LOGGER.info("MinioUtil | listObjectNames | listObjectNames size : " + listObjectNames.size()); 197 | 198 | return listObjectNames; 199 | } 200 | 201 | // Delete object from the specified bucket 202 | @SneakyThrows 203 | public boolean removeObject(String bucketName, String objectName) { 204 | 205 | LOGGER.info("MinioUtil | removeObject is called"); 206 | 207 | boolean flag = bucketExists(bucketName); 208 | 209 | LOGGER.info("MinioUtil | removeObject | flag : " + flag); 210 | 211 | if (flag) { 212 | minioClient.removeObject( 213 | RemoveObjectArgs.builder().bucket(bucketName).object(objectName).build()); 214 | return true; 215 | } 216 | return false; 217 | } 218 | 219 | // Get file path from the specified bucket 220 | @SneakyThrows 221 | public String getObjectUrl(String bucketName, String objectName) { 222 | 223 | LOGGER.info("MinioUtil | getObjectUrl is called"); 224 | boolean flag = bucketExists(bucketName); 225 | LOGGER.info("MinioUtil | getObjectUrl | flag : " + flag); 226 | 227 | String url = ""; 228 | 229 | if (flag) { 230 | url = minioClient.getPresignedObjectUrl( 231 | GetPresignedObjectUrlArgs.builder() 232 | .method(Method.GET) 233 | .bucket(bucketName) 234 | .object(objectName) 235 | .expiry(2, TimeUnit.MINUTES) 236 | .build()); 237 | LOGGER.info("MinioUtil | getObjectUrl | url : " + url); 238 | } 239 | return url; 240 | } 241 | 242 | // Get metadata of the object from the specified bucket 243 | @SneakyThrows 244 | public StatObjectResponse statObject(String bucketName, String objectName) { 245 | LOGGER.info("MinioUtil | statObject is called"); 246 | 247 | boolean flag = bucketExists(bucketName); 248 | LOGGER.info("MinioUtil | statObject | flag : " + flag); 249 | if (flag) { 250 | StatObjectResponse stat = 251 | minioClient.statObject( 252 | StatObjectArgs.builder().bucket(bucketName).object(objectName).build()); 253 | 254 | LOGGER.info("MinioUtil | statObject | stat : " + stat.toString()); 255 | 256 | return stat; 257 | } 258 | return null; 259 | } 260 | 261 | // Get a file object as a stream from the specified bucket 262 | @SneakyThrows 263 | public InputStream getObject(String bucketName, String objectName) { 264 | LOGGER.info("MinioUtil | getObject is called"); 265 | 266 | boolean flag = bucketExists(bucketName); 267 | LOGGER.info("MinioUtil | getObject | flag : " + flag); 268 | 269 | if (flag) { 270 | StatObjectResponse statObject = statObject(bucketName, objectName); 271 | if (statObject != null && statObject.size() > 0) { 272 | InputStream stream = 273 | minioClient.getObject( 274 | GetObjectArgs.builder() 275 | .bucket(bucketName) 276 | .object(objectName) 277 | .build()); 278 | 279 | LOGGER.info("MinioUtil | getObject | stream : " + stream.toString()); 280 | return stream; 281 | } 282 | } 283 | return null; 284 | } 285 | 286 | // Get a file object as a stream from the specified bucket ( Breakpoint download ) 287 | @SneakyThrows 288 | public InputStream getObject(String bucketName, String objectName, long offset, Long length) { 289 | 290 | LOGGER.info("MinioUtil | getObject is called"); 291 | 292 | boolean flag = bucketExists(bucketName); 293 | LOGGER.info("MinioUtil | getObject | flag : " + flag); 294 | 295 | if (flag) { 296 | StatObjectResponse statObject = statObject(bucketName, objectName); 297 | if (statObject != null && statObject.size() > 0) { 298 | InputStream stream = 299 | minioClient.getObject( 300 | GetObjectArgs.builder() 301 | .bucket(bucketName) 302 | .object(objectName) 303 | .offset(offset) 304 | .length(length) 305 | .build()); 306 | 307 | LOGGER.info("MinioUtil | getObject | stream : " + stream.toString()); 308 | return stream; 309 | } 310 | } 311 | return null; 312 | } 313 | 314 | // Delete multiple file objects from the specified bucket 315 | @SneakyThrows 316 | public boolean removeObject(String bucketName, List objectNames) { 317 | LOGGER.info("MinioUtil | removeObject is called"); 318 | 319 | boolean flag = bucketExists(bucketName); 320 | LOGGER.info("MinioUtil | removeObject | flag : " + flag); 321 | 322 | if (flag) { 323 | List objects = new LinkedList<>(); 324 | for (int i = 0; i < objectNames.size(); i++) { 325 | objects.add(new DeleteObject(objectNames.get(i))); 326 | } 327 | Iterable> results = 328 | minioClient.removeObjects( 329 | RemoveObjectsArgs.builder().bucket(bucketName).objects(objects).build()); 330 | 331 | for (Result result : results) { 332 | DeleteError error = result.get(); 333 | 334 | LOGGER.info("MinioUtil | removeObject | error : " + error.objectName() + " " + error.message()); 335 | 336 | return false; 337 | } 338 | } 339 | return true; 340 | } 341 | 342 | // Upload InputStream object to the specified bucket 343 | @SneakyThrows 344 | public boolean putObject(String bucketName, String objectName, InputStream inputStream, String contentType) { 345 | 346 | LOGGER.info("MinioUtil | putObject is called"); 347 | 348 | boolean flag = bucketExists(bucketName); 349 | LOGGER.info("MinioUtil | putObject | flag : " + flag); 350 | 351 | if (flag) { 352 | minioClient.putObject( 353 | PutObjectArgs.builder().bucket(bucketName).object(objectName).stream( 354 | inputStream, -1, minioConfig.getFileSize()) 355 | .contentType(contentType) 356 | .build()); 357 | StatObjectResponse statObject = statObject(bucketName, objectName); 358 | 359 | LOGGER.info("MinioUtil | putObject | statObject != null : " + (statObject != null)); 360 | LOGGER.info("MinioUtil | putObject | statObject.size() : " + statObject.size()); 361 | 362 | if (statObject != null && statObject.size() > 0) { 363 | return true; 364 | } 365 | } 366 | return false; 367 | } 368 | } 369 | -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8085 3 | spring: 4 | application: 5 | name: springboot-minio 6 | minio: 7 | endpoint: http://127.0.0.1:9000 8 | port: 9000 9 | accessKey: minioadmin #Login Account 10 | secretKey: minioadmin # Login Password 11 | secure: false 12 | bucket-name: commons # Bucket Name 13 | image-size: 10485760 # Maximum size of picture file 14 | file-size: 1073741824 # Maximum file size 15 | -------------------------------------------------------------------------------- /src/test/java/com/springminio/app/AppApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springminio.app; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class AppApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | --------------------------------------------------------------------------------