use of com.qcloud.cos.model.ObjectMetadata in project alluxio by Alluxio.
the class COSUnderFileSystem method createEmptyObject.
@Override
public boolean createEmptyObject(String key) {
try {
ObjectMetadata objMeta = new ObjectMetadata();
objMeta.setContentLength(0);
mClient.putObject(mBucketNameInternal, key, new ByteArrayInputStream(new byte[0]), objMeta);
return true;
} catch (CosClientException e) {
LOG.error("Failed to create object: {}", key, e);
return false;
}
}
use of com.qcloud.cos.model.ObjectMetadata in project jeesuite-libs by vakinge.
the class QcloudProvider method upload.
@Override
public CUploadResult upload(CUploadObject object) {
PutObjectRequest request;
String fileKey = object.getFileKey();
String bucketName = buildBucketName(object.getBucketName());
if (object.getFile() != null) {
request = new PutObjectRequest(bucketName, fileKey, object.getFile());
} else if (object.getBytes() != null) {
ByteArrayInputStream inputStream = new ByteArrayInputStream(object.getBytes());
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(object.getFileSize());
request = new PutObjectRequest(bucketName, fileKey, inputStream, objectMetadata);
} else if (object.getInputStream() != null) {
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(object.getFileSize());
request = new PutObjectRequest(bucketName, fileKey, object.getInputStream(), objectMetadata);
} else {
throw new IllegalArgumentException("upload object is NULL");
}
try {
if (object.getFileSize() > conf.getMaxAllowdSingleFileSize()) {
Upload upload = transferManager.upload(request);
com.qcloud.cos.model.UploadResult result = upload.waitForUploadResult();
return new CUploadResult(fileKey, getFullPath(object.getBucketName(), fileKey), result.getCrc64Ecma());
} else {
PutObjectResult result = cosclient.putObject(request);
return new CUploadResult(fileKey, getFullPath(object.getBucketName(), fileKey), result.getContentMd5());
}
} catch (Exception e) {
e.printStackTrace();
throw new JeesuiteBaseException(500, buildMessage(bucketName, e));
}
}
use of com.qcloud.cos.model.ObjectMetadata in project roof-im by madfroglx.
the class OCSTest method testUpload.
@Test
public void testUpload() {
// 用户基本信息
String appid = "1255710173";
String secret_id = "AKID3A9jOoqatjrh6k7UjyKfA5N6q4olSaB6";
String secret_key = "Qdr0efEb3NicSkED2UsKaQ8ANaPorDWr";
String sessionToken = "81ca8cc5fb84bd42ac36c40515917b308ad333d830001";
// 设置秘钥
COSCredentials cred = new BasicCOSCredentials(appid, secret_id, secret_key);
// 设置区域, 这里设置为华北
ClientConfig clientConfig = new ClientConfig(new Region("ap-shanghai"));
// 生成 cos 客户端对象
COSClient cosClient = new COSClient(cred, clientConfig);
// 创建 bucket
// bucket 数量上限 200 个, bucket 是重操作, 一般不建议创建如此多的 bucket
// 重复创建同名 bucket 会报错
String bucketName = "im";
// 上传 object, 建议 20M 以下的文件使用该接口
File localFile = new File("E:\\excel\\test.txt");
String key = "im/zlt/test4";
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setSecurityToken(sessionToken);
putObjectRequest.setMetadata(objectMetadata);
PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
System.out.println(putObjectResult);
// 关闭客户端 (关闭后台线程)
cosClient.shutdown();
}
use of com.qcloud.cos.model.ObjectMetadata in project jeesuite-libs by vakinge.
the class QcloudProvider method upload.
@Override
public CUploadResult upload(CUploadObject object) {
PutObjectRequest request;
String fileKey = object.getFileKey();
String bucketName = buildBucketName(object.getBucketName());
if (object.getFile() != null) {
request = new PutObjectRequest(bucketName, fileKey, object.getFile());
} else if (object.getBytes() != null) {
ByteArrayInputStream inputStream = new ByteArrayInputStream(object.getBytes());
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(object.getFileSize());
request = new PutObjectRequest(bucketName, fileKey, inputStream, objectMetadata);
} else if (object.getInputStream() != null) {
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(object.getFileSize());
request = new PutObjectRequest(bucketName, fileKey, object.getInputStream(), objectMetadata);
} else {
throw new IllegalArgumentException("upload object is NULL");
}
try {
if (object.getFileSize() > conf.getMaxAllowdSingleFileSize()) {
Upload upload = transferManager.upload(request);
com.qcloud.cos.model.UploadResult result = upload.waitForUploadResult();
return new CUploadResult(fileKey, getFullPath(object.getBucketName(), fileKey), result.getCrc64Ecma());
} else {
PutObjectResult result = cosclient.putObject(request);
return new CUploadResult(fileKey, getFullPath(object.getBucketName(), fileKey), result.getContentMd5());
}
} catch (Exception e) {
e.printStackTrace();
throw new JeesuiteBaseException(500, buildMessage(bucketName, e));
}
}
use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class PutGetDelTest method testPutObjectWithChineseContentDisposition.
@Test
public void testPutObjectWithChineseContentDisposition() throws IOException {
ObjectMetadata originObjectMeta = new ObjectMetadata();
String disposition = "attachment;filename=\"" + UrlEncoderUtils.encode(new String("测试文件.txt".getBytes(), "UTF-8")) + ".jpg\"";
originObjectMeta.setContentDisposition(disposition);
testPutObjectByStreamDiffSize(0L, originObjectMeta);
}
Aggregations