// 创建MinioClient
MinioClient minioClient = new MinioClient(endPoint, accessKey, secretAccessKey);
// 获取对象的元数据, 如果对象不存在则抛出异常
public ObjectStat statObject(String bucketName, String objectName)
try {
ObjectStat objectStat = minioClient.statObject("mybucket", "myobject");
} catch(MinioException e) {
log.error(e.getMessage());
}
public ObjectStat statObject(String bucketName, String objectName, ServerSideEncryption sse)
/**
* 将给定的文件最为对象上传到指定的bucket
* 如果对象的大小超过5MB,客户端将自动使用多重会话(multipart session)
*
* 如果多重会话失败,已经上传的部分将被自动流产
* @param bucketName : Name of the bucket
* @param objectName : Object name in the bucket
* @param fileName : File name to upload
* @param contentType : File content type of the object, user supplied
*/
public void putObject(String bucketName, String objectName, String fileName, String contentType)
try {
minioClient.putObject("mybucket", "island.jpg", "/mnt/photos/island.jpg", "application/octet-stream")
} catch(MinioException e) {
log.error(e.getMessage());
}
/**
* 将给定的数据流作为对象上传到给定的bucket中,流的大小未知
* 如果过流中有超过525MiB的数据, 客户端将自动使用多重会话(multipart session)
*
* 如果多重会话失败,已经上传的部分将被自动流产
* @param bucketName : Name of the bucket
* @param objectName : Object name in the bucket
* @param stream : stream to upload
* @param contentType : File content type of the object, user supplied
*/
public void putObject(String bucketName, String objectName, InputStream stream, String contentType)
StringBuilder builder = new StringBuilder();
builder.append("");
ByteArrayInputStream bais = new ByteArrayInputStream(builder.toString().getBytes("UTF-8");
minioClient.putObject("my-bucketname", "my-objectname", bais, "application/octet-stream");
bais.close();
/**
* @param size : Size of the data to read from stream that will be uploaded
*/
public void pubObject(String bucketName, String objectName, InputStream stream, long size, String contentType)
/**
* 上传fileName文件的内容到objectName对象中
* @param objectName : Object name in the bucket
*/
public void putObject(String bucketName, String objectName, String fileName)
/**
* @param sse : 服务器端的加密形式
*/
public void putObject(String bucketName, String objectName, InputStream stream, long size, ServerSideEncryption sse)
/**
* 将流作为对象上传到指定的bucket中,使用特定的元数据
* @param headerMap : 自定义/额外 对象的元数据
*/
public void putObject(String bucketName, String objectName, InputStream stream, long size, Map headerMap)
...
/**
* Downloads an object as stream
* The InputStream must be closed after use else the connection will remain open.
*/
public InputStream getObject(String bucketName, String objectName)
try {
// 如果没有找到对象,将抛出exception
minioClient.statObject("mybucket", "myobject");
InputStream stream = minioClient.getObject("mybucket", "myobject");
...
stream.close();
} catch (MinioException e) {
log.error(e.getMessage());
}
// 从offset处开始获取对象数据
public InputStream getObject(String bucketName, String objectName, long offset)
// 从offset出获取指定长度对象数据
public InputStream getObject(String bucketName, String objectName, long offset, Long length)
// 将对象作为文件保存到本地文件系统
public void getObject(String bucketName, String objectName, String fileName)
public InputStream getObject(String bucketName, String objectName, ServerSideEncryption sse)
// 返回一个临时URL地址,用来下载bucket 中的object对象,使用默认的过期时间。默认过期时间为7天,单位为秒。
public String presignedGetObject(String bucketName, String objectName)
/**
* @Param expires : 过期时间,单位为秒,默认7天
* @Return Url : 文件url
*/
public String presignedGetObject(String bucketName, String objectName, Integer expires)
/**
* 上传文件,并返回文件下载url,设置默认过期时间为7天,单位为秒
* @Return url : 文件下载的url
*/
public String presignedPutObject(String bucketName, String objectName)
/**
* 上传文件,并返回文件下载url,设置过期时间,单位为秒
* @Return url : 文件下载的url
*/
public String presignedPutObject(String bucketName, String objectName, Integer expires)
Java Client API Reference