io.minio.MinioClient Java Examples
The following examples show how to use
io.minio.MinioClient.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThumbnailsFunction.java From docs with Apache License 2.0 | 6 votes |
/** * Uploads the provided data to the storage server, as an object named as specified. * * @param imageBuffer the image data to upload * @param objectName the name of the remote object to create */ private void objectUpload(byte[] imageBuffer, String objectName) { try { MinioClient minioClient = new MinioClient(storageUrl, storageAccessKey, storageSecretKey); // Ensure the bucket exists. if(!minioClient.bucketExists("alpha")) { minioClient.makeBucket("alpha"); } // Upload the image to the bucket with putObject minioClient.putObject("alpha", objectName, new ByteArrayInputStream(imageBuffer), imageBuffer.length, "application/octet-stream"); } catch(Exception e) { System.err.println("Error occurred: " + e); e.printStackTrace(); } }
Example #2
Source File: MinioController.java From jeecg-cloud with Apache License 2.0 | 6 votes |
/** * 下载minio服务的文件 * * @param response * @return */ @GetMapping("download") public String download(HttpServletResponse response) { try { MinioClient minioClient = new MinioClient(url, accessKey, secretKey); InputStream fileInputStream = minioClient.getObject(bucketName, "11.jpg"); response.setHeader("Content-Disposition", "attachment;filename=" + "11.jpg"); response.setContentType("application/force-download"); response.setCharacterEncoding("UTF-8"); IOUtils.copy(fileInputStream, response.getOutputStream()); return "下载完成"; } catch (Exception e) { e.printStackTrace(); return "下载失败"; } }
Example #3
Source File: MinioController.java From jeecg-boot with Apache License 2.0 | 6 votes |
/** * 下载minio服务的文件 * * @param response * @return */ @GetMapping("download") public String download(HttpServletResponse response) { try { MinioClient minioClient = new MinioClient(url, accessKey, secretKey); InputStream fileInputStream = minioClient.getObject(bucketName, "11.jpg"); response.setHeader("Content-Disposition", "attachment;filename=" + "11.jpg"); response.setContentType("application/force-download"); response.setCharacterEncoding("UTF-8"); IOUtils.copy(fileInputStream, response.getOutputStream()); return "下载完成"; } catch (Exception e) { e.printStackTrace(); return "下载失败"; } }
Example #4
Source File: CacheService.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
@Autowired public CacheService( @Value("${minio.endpoint}") String minioEndpoint, @Value("${minio.accesskey}") String accessKey, @Value("${minio.secretkey}") String secretKey ) throws InvalidEndpointException, InvalidPortException { this.minioClient = new MinioClient(minioEndpoint, accessKey, secretKey); }
Example #5
Source File: MinioClientComponentImpl.java From sctalk with Apache License 2.0 | 6 votes |
@PostConstruct public void init() { try { logger.info("init minio client start"); if (minioConfig == null) { logger.warn("MINIO未正确配置,文件上传服务将不可用"); } else { minioClient = new MinioClient(minioConfig.getEndpoint(), minioConfig.getPort(), minioConfig.getAccessKey(), minioConfig.getSecretKey()); } } catch (InvalidEndpointException | InvalidPortException e) { logger.warn("MINIO未正确配置,文件上传服务将不可用", e); } finally { logger.info("init minio client end"); } }
Example #6
Source File: StorageConfig.java From flow-platform-x with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnProperty(name = "app.minio.enabled", havingValue = "true") public MinioClient minioClient() throws InvalidPortException, InvalidEndpointException { URL endpoint = minioProperties.getEndpoint(); String key = minioProperties.getKey(); String secret = minioProperties.getSecret(); return new MinioClient(endpoint, key, secret); }
Example #7
Source File: AdminStorageAction.java From fess with Apache License 2.0 | 5 votes |
protected static MinioClient createClient(final FessConfig fessConfig) { try { return new MinioClient(fessConfig.getStorageEndpoint(), fessConfig.getStorageAccessKey(), fessConfig.getStorageSecretKey()); } catch (final Exception e) { throw new StorageException("Failed to create MinioClient: " + fessConfig.getStorageEndpoint(), e); } }
Example #8
Source File: MinioController.java From mall with Apache License 2.0 | 5 votes |
@ApiOperation("文件上传") @RequestMapping(value = "/upload", method = RequestMethod.POST) @ResponseBody public CommonResult upload(@RequestParam("file") MultipartFile file) { try { //创建一个MinIO的Java客户端 MinioClient minioClient = new MinioClient(ENDPOINT, ACCESS_KEY, SECRET_KEY); boolean isExist = minioClient.bucketExists(BUCKET_NAME); if (isExist) { LOGGER.info("存储桶已经存在!"); } else { //创建存储桶并设置只读权限 minioClient.makeBucket(BUCKET_NAME); minioClient.setBucketPolicy(BUCKET_NAME, "*.*", PolicyType.READ_ONLY); } String filename = file.getOriginalFilename(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); // 设置存储对象名称 String objectName = sdf.format(new Date()) + "/" + filename; // 使用putObject上传一个文件到存储桶中 minioClient.putObject(BUCKET_NAME, objectName, file.getInputStream(), file.getContentType()); LOGGER.info("文件上传成功!"); MinioUploadDto minioUploadDto = new MinioUploadDto(); minioUploadDto.setName(filename); minioUploadDto.setUrl(ENDPOINT + "/" + BUCKET_NAME + "/" + objectName); return CommonResult.success(minioUploadDto); } catch (Exception e) { LOGGER.info("上传发生错误: {}!", e.getMessage()); } return CommonResult.failed(); }
Example #9
Source File: MinioController.java From mall with Apache License 2.0 | 5 votes |
@ApiOperation("文件删除") @RequestMapping(value = "/delete", method = RequestMethod.POST) @ResponseBody public CommonResult delete(@RequestParam("objectName") String objectName) { try { MinioClient minioClient = new MinioClient(ENDPOINT, ACCESS_KEY, SECRET_KEY); minioClient.removeObject(BUCKET_NAME, objectName); return CommonResult.success(null); } catch (Exception e) { e.printStackTrace(); } return CommonResult.failed(); }
Example #10
Source File: MinioController.java From jeecg-boot with Apache License 2.0 | 5 votes |
/** * 上传文件到minio服务 * * @param file * @return */ @PostMapping("upload") public String upload(@RequestParam("file") MultipartFile file) { try { MinioClient minioClient = new MinioClient(url, accessKey, secretKey); InputStream is = file.getInputStream(); //得到文件流 String fileName = "/upload/img/" + file.getOriginalFilename(); //文件名 String contentType = file.getContentType(); //类型 minioClient.putObject(bucketName, fileName, is, contentType); //把文件放置Minio桶(文件夹) return "上传成功"; } catch (Exception e) { return "上传失败"; } }
Example #11
Source File: FileClient.java From file-service with Apache License 2.0 | 5 votes |
private void initMinioClient() throws InvalidEndpointException, InvalidPortException { if (fileClientConfig.getRegion() != null) { this.minioClient = new MinioClient( fileClientConfig.getEndpoint(), fileClientConfig.getAccessKey(), fileClientConfig.getSecretKey(), fileClientConfig.getRegion()); } else { this.minioClient = new MinioClient( fileClientConfig.getEndpoint(), fileClientConfig.getAccessKey(), fileClientConfig.getSecretKey()); } }
Example #12
Source File: StorageConfig.java From flow-platform-x with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnProperty(name = "app.minio.enabled", havingValue = "true") public MinioClient minioClient() throws InvalidPortException, InvalidEndpointException { URL endpoint = minioProperties.getEndpoint(); String key = minioProperties.getKey(); String secret = minioProperties.getSecret(); return new MinioClient(endpoint, key, secret); }
Example #13
Source File: AlbumDao.java From minio-java-rest-example with Apache License 2.0 | 5 votes |
public List<Album> listAlbums() throws NoSuchAlgorithmException, IOException, InvalidKeyException, XmlPullParserException, MinioException { List<Album> list = new ArrayList<Album>(); final String minioBucket = "albums"; // Initialize minio client object. MinioClient minioClient = new MinioClient("play.minio.io", 9000, "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"); // List all objects. Iterable<Result<Item>> myObjects = minioClient.listObjects(minioBucket); // Iterate over each elements and set album url. for (Result<Item> result : myObjects) { Item item = result.get(); System.out.println(item.lastModified() + ", " + item.size() + ", " + item.objectName()); // Generate a presigned URL which expires in a day url = minioClient.presignedGetObject(minioBucket, item.objectName(), 60 * 60 * 24); // Create a new Album Object Album album = new Album(); // Set the presigned URL in the album object album.setUrl(url); // Add the album object to the list holding Album objects list.add(album); } // Return list of albums. return list; }
Example #14
Source File: CacheUploader.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
public CacheUploader(MinioClient minioClient, String minioBucket, Archive archive, byte[] data) { this.minioClient = minioClient; this.minioBucket = minioBucket; this.archive = archive; this.data = data; }
Example #15
Source File: CacheUpdater.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
@Autowired public CacheUpdater( @Qualifier("Runelite Cache SQL2O") Sql2o sql2o, MinioClient minioClient ) { this.sql2o = sql2o; this.minioClient = minioClient; }
Example #16
Source File: S3CacheManager.java From simpleci with MIT License | 5 votes |
@Override public void uploadCache(JobOutputProcessor outputProcessor, String cachePath) { try { outputProcessor.output(String.format("Uploading cache file %s to s3 server %s\n", cachePath, settings.endPoint)); MinioClient minioClient = new MinioClient(settings.endPoint, settings.accessKey, settings.secretKey); minioClient.putObject(settings.bucketName, cacheFileName, cachePath); outputProcessor.output("Cache uploaded\n"); } catch (Exception e) { outputProcessor.output("Error upload cache: " + e.getMessage() + "\n"); } }
Example #17
Source File: MinioStoreConfig.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Bean public MinioClientFacade minioClientFacade() { MinioClient minioClient; try { minioClient = minioClientFactory().createClient(); } catch (IOException e) { throw new UncheckedIOException(e); } return new MinioClientFacade(minioClient, bucketName); }
Example #18
Source File: AdminStorageAction.java From fess with Apache License 2.0 | 5 votes |
public static void uploadObject(final String objectName, final MultipartFormFile uploadFile) { try (final InputStream in = uploadFile.getInputStream()) { final FessConfig fessConfig = ComponentUtil.getFessConfig(); final MinioClient minioClient = createClient(fessConfig); minioClient.putObject(fessConfig.getStorageBucket(), objectName, in, new PutObjectOptions(uploadFile.getFileSize(), -1)); } catch (final Exception e) { throw new StorageException("Failed to upload " + objectName, e); } }
Example #19
Source File: AdminStorageAction.java From fess with Apache License 2.0 | 5 votes |
public static void deleteObject(final String objectName) { try { final FessConfig fessConfig = ComponentUtil.getFessConfig(); final MinioClient minioClient = createClient(fessConfig); minioClient.removeObject(fessConfig.getStorageBucket(), objectName); } catch (final Exception e) { throw new StorageException("Failed to delete " + objectName, e); } }
Example #20
Source File: MinIOFileManage.java From sk-admin with Apache License 2.0 | 5 votes |
/** * 如果存储桶不存在 创建存储通 * * @param os * @param minioClient * @throws Exception */ private void checkBucket(OssSetting os, MinioClient minioClient) throws Exception { // 如果存储桶不存在 创建存储通 if (!minioClient.bucketExists(os.getBucket())) { minioClient.makeBucket(os.getBucket()); // 设置隐私权限 公开读 String builder = "{\n" + " \"Statement\": [\n" + " {\n" + " \"Action\": [\n" + " \"s3:GetBucketLocation\",\n" + " \"s3:ListBucket\"\n" + " ],\n" + " \"Effect\": \"Allow\",\n" + " \"Principal\": \"*\",\n" + " \"Resource\": \"arn:aws:s3:::" + os.getBucket() + "\"\n" + " },\n" + " {\n" + " \"Action\": \"s3:GetObject\",\n" + " \"Effect\": \"Allow\",\n" + " \"Principal\": \"*\",\n" + " \"Resource\": \"arn:aws:s3:::" + os.getBucket() + "/*\"\n" + " }\n" + " ],\n" + " \"Version\": \"2012-10-17\"\n" + "}\n"; minioClient.setBucketPolicy(os.getBucket(), builder); } }
Example #21
Source File: KnoteJavaApplication.java From knote-java with Apache License 2.0 | 5 votes |
private void initMinio() throws InterruptedException { boolean success = false; while (!success) { try { minioClient = new MinioClient("http://" + properties.getMinioHost() + ":9000" , properties.getMinioAccessKey(), properties.getMinioSecretKey(), false); // Check if the bucket already exists. boolean isExist = minioClient.bucketExists(properties.getMinioBucket()); if (isExist) { System.out.println("> Bucket already exists."); } else { minioClient.makeBucket(properties.getMinioBucket()); } success = true; } catch (Exception e) { e.printStackTrace(); System.out.println("> Minio Reconnect: " + properties.isMinioReconnectEnabled()); if (properties.isMinioReconnectEnabled()) { Thread.sleep(5000); } else { success = true; } } } System.out.println("> Minio initialized!"); }
Example #22
Source File: MinIOFileManage.java From sk-admin with Apache License 2.0 | 5 votes |
@Override public String pathUpload(String filePath, String key) { OssSetting os = getOssSetting(); try { MinioClient minioClient = new MinioClient(os.getHttp() + os.getEndpoint(), os.getAccessKey(), os.getSecretKey()); checkBucket(os, minioClient); minioClient.putObject(os.getBucket(), key, filePath, null, null, null, null); } catch (Exception e) { throw new SkException("上传出错,请检查MinIO配置"); } return os.getHttp() + os.getEndpoint() + "/" + os.getBucket() + "/" + key; }
Example #23
Source File: MinIOFileManage.java From sk-admin with Apache License 2.0 | 5 votes |
@Override public String inputStreamUpload(InputStream inputStream, String key, MultipartFile file) { OssSetting os = getOssSetting(); try { MinioClient minioClient = new MinioClient(os.getHttp() + os.getEndpoint(), os.getAccessKey(), os.getSecretKey()); checkBucket(os, minioClient); minioClient.putObject(os.getBucket(), key, inputStream, file.getSize(), null, null, file.getContentType()); } catch (Exception e) { throw new SkException("上传出错,请检查MinIO配置"); } return os.getHttp() + os.getEndpoint() + "/" + os.getBucket() + "/" + key; }
Example #24
Source File: MinIOFileManage.java From sk-admin with Apache License 2.0 | 5 votes |
@Override public String copyFile(String fromKey, String toKey) { OssSetting os = getOssSetting(); try { MinioClient minioClient = new MinioClient(os.getHttp() + os.getEndpoint(), os.getAccessKey(), os.getSecretKey()); checkBucket(os, minioClient); minioClient.copyObject(os.getBucket(), fromKey, null, null, os.getBucket(), toKey, null, null); } catch (Exception e) { throw new SkException("拷贝文件出错,请检查MinIO配置"); } return os.getHttp() + os.getEndpoint() + "/" + os.getBucket() + "/" + toKey; }
Example #25
Source File: MinIOFileManage.java From sk-admin with Apache License 2.0 | 5 votes |
@Override public void deleteFile(String key) { OssSetting os = getOssSetting(); try { MinioClient minioClient = new MinioClient(os.getHttp() + os.getEndpoint(), os.getAccessKey(), os.getSecretKey()); checkBucket(os, minioClient); minioClient.removeObject(os.getBucket(), key); } catch (Exception e) { throw new SkException("删除文件出错,请检查MinIO配置"); } }
Example #26
Source File: MinioTemplate.java From beihu-boot with Apache License 2.0 | 5 votes |
/** * Bucket Operations */ public void createBucket(String bucketName) throws XmlPullParserException, NoSuchAlgorithmException, InvalidKeyException, IOException, RegionConflictException, NoResponseException, InternalException, ErrorResponseException, InsufficientDataException, InvalidBucketNameException { MinioClient client = getMinioClient(); if(!client.bucketExists(bucketName)){ client.makeBucket(bucketName); } }
Example #27
Source File: MinIoAutoConfiguration.java From magic-starter with GNU Lesser General Public License v3.0 | 5 votes |
@Bean @SneakyThrows @ConditionalOnMissingBean public MinioClient minioClient() { return new MinioClient(ossProperties.getMinIo() .getEndpoint(), ossProperties.getMinIo() .getAccessKey(), ossProperties.getMinIo() .getSecretKey()); }
Example #28
Source File: MinioController.java From mall-learning with Apache License 2.0 | 5 votes |
@ApiOperation("文件上传") @RequestMapping(value = "/upload", method = RequestMethod.POST) @ResponseBody public CommonResult upload(@RequestParam("file") MultipartFile file) { try { //创建一个MinIO的Java客户端 MinioClient minioClient = new MinioClient(ENDPOINT, ACCESS_KEY, SECRET_KEY); boolean isExist = minioClient.bucketExists(BUCKET_NAME); if (isExist) { LOGGER.info("存储桶已经存在!"); } else { //创建存储桶并设置只读权限 minioClient.makeBucket(BUCKET_NAME); minioClient.setBucketPolicy(BUCKET_NAME, "*.*", PolicyType.READ_ONLY); } String filename = file.getOriginalFilename(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); // 设置存储对象名称 String objectName = sdf.format(new Date()) + "/" + filename; // 使用putObject上传一个文件到存储桶中 minioClient.putObject(BUCKET_NAME, objectName, file.getInputStream(), file.getContentType()); LOGGER.info("文件上传成功!"); MinioUploadDto minioUploadDto = new MinioUploadDto(); minioUploadDto.setName(filename); minioUploadDto.setUrl(ENDPOINT + "/" + BUCKET_NAME + "/" + objectName); return CommonResult.success(minioUploadDto); } catch (Exception e) { LOGGER.info("上传发生错误: {}!", e.getMessage()); } return CommonResult.failed(); }
Example #29
Source File: MinioController.java From jeecg-cloud with Apache License 2.0 | 5 votes |
/** * 上传文件到minio服务 * * @param file * @return */ @PostMapping("upload") public String upload(@RequestParam("file") MultipartFile file) { try { MinioClient minioClient = new MinioClient(url, accessKey, secretKey); InputStream is = file.getInputStream(); //得到文件流 String fileName = "/upload/img/" + file.getOriginalFilename(); //文件名 String contentType = file.getContentType(); //类型 minioClient.putObject(bucketName, fileName, is, contentType); //把文件放置Minio桶(文件夹) return "上传成功"; } catch (Exception e) { return "上传失败"; } }
Example #30
Source File: MinioController.java From mall-swarm with Apache License 2.0 | 5 votes |
@ApiOperation("文件删除") @RequestMapping(value = "/delete", method = RequestMethod.POST) @ResponseBody public CommonResult delete(@RequestParam("objectName") String objectName) { try { MinioClient minioClient = new MinioClient(ENDPOINT, ACCESS_KEY, SECRET_KEY); minioClient.removeObject(BUCKET_NAME, objectName); return CommonResult.success(null); } catch (Exception e) { e.printStackTrace(); } return CommonResult.failed(); }