use of com.aliyun.oss.model.CreateBucketRequest in project CBEC-B2B by A-Cubic.
the class OSSUtils method uploadOSSToInputStream.
public static void uploadOSSToInputStream(InputStream in, String filename) {
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
try {
if (!ossClient.doesBucketExist(bucketName)) {
System.out.println("Creating bucket " + bucketName + "\n");
ossClient.createBucket(bucketName);
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
createBucketRequest.setCannedACL(CannedAccessControlList.PublicRead);
ossClient.createBucket(createBucketRequest);
}
ossClient.putObject(new PutObjectRequest(bucketName, key + "/" + filename, in));
} catch (Exception e) {
logger.error("上传oss失败,原因:" + e.getMessage());
} finally {
ossClient.shutdown();
}
}
use of com.aliyun.oss.model.CreateBucketRequest in project aliyun-oss-java-sdk by aliyun.
the class OSSClientRequestTest method testCreateBucketRequest.
@Test
public void testCreateBucketRequest() {
TestAction test = new TestAction() {
@Override
public void run() throws Exception {
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
createBucketRequest.setLocationConstraint(LocationConstraint.OSS_CN_QINGDAO);
bucketOp.createBucket(createBucketRequest);
}
};
String requestXml = "<CreateBucketConfiguration><LocationConstraint>oss-cn-qingdao</LocationConstraint></CreateBucketConfiguration>";
executeTest(test, HttpMethod.PUT, bucketName + "." + endpoint.getHost(), "", null, requestXml, requestXml.length());
}
use of com.aliyun.oss.model.CreateBucketRequest in project aliyun-oss-java-sdk by aliyun.
the class CreateBucketTest method testPutWithStorageTypeAndLocation.
@Test
public void testPutWithStorageTypeAndLocation() {
final String bucketName = "bucket-with-storage-and-location";
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
createBucketRequest.setStorageClass(StorageClass.Standard);
createBucketRequest.setLocationConstraint(OSS_TEST_REGION);
try {
ossClient.createBucket(createBucketRequest);
AccessControlList returnedAcl = ossClient.getBucketAcl(bucketName);
Set<Grant> grants = returnedAcl.getGrants();
Assert.assertEquals(0, grants.size());
System.out.println(returnedAcl.toString());
BucketList buckets = ossClient.listBuckets(bucketName, "", 100);
Assert.assertEquals(1, buckets.getBucketList().size());
Assert.assertEquals(StorageClass.Standard, buckets.getBucketList().get(0).getStorageClass());
Assert.assertEquals(OSS_TEST_REGION, buckets.getBucketList().get(0).getLocation());
Assert.assertEquals(buckets.getRequestId().length(), REQUEST_ID_LEN);
} catch (Exception ex) {
Assert.fail(ex.getMessage());
} finally {
ossClient.deleteBucket(bucketName);
}
}
use of com.aliyun.oss.model.CreateBucketRequest in project aliyun-oss-java-sdk by aliyun.
the class CreateBucketTest method testPutWithStorageTypeCompatibility.
@Test
public void testPutWithStorageTypeCompatibility() {
final String bucketName = "bucket-with-storage-type-compatibility";
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
try {
ossClient.createBucket(createBucketRequest);
BucketList buckets = ossClient.listBuckets(bucketName, "", 100);
Assert.assertEquals(1, buckets.getBucketList().size());
Assert.assertEquals(StorageClass.Standard, buckets.getBucketList().get(0).getStorageClass());
Assert.assertEquals(buckets.getRequestId().length(), REQUEST_ID_LEN);
} catch (Exception ex) {
Assert.fail(ex.getMessage());
} finally {
ossClient.deleteBucket(bucketName);
}
}
use of com.aliyun.oss.model.CreateBucketRequest in project aliyun-oss-java-sdk by aliyun.
the class CreateBucketTest method testPutWithDefaultStorageType.
@Test
public void testPutWithDefaultStorageType() {
final String bucketName = "bucket-with-default-storage-type";
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
try {
ossClient.createBucket(createBucketRequest);
BucketList buckets = ossClient.listBuckets(bucketName, "", 100);
Assert.assertEquals(1, buckets.getBucketList().size());
Assert.assertEquals(StorageClass.Standard, buckets.getBucketList().get(0).getStorageClass());
Assert.assertEquals(buckets.getRequestId().length(), REQUEST_ID_LEN);
} catch (Exception ex) {
Assert.fail(ex.getMessage());
} finally {
ossClient.deleteBucket(bucketName);
}
}
Aggregations