Search in sources :

Example 1 with GroupGrantee

use of com.amazonaws.services.s3.model.GroupGrantee in project quickutil by quickutil.

the class AWSS3Util method uploadFile.

/**
 * 上传
 *
 * @param s3Name-S3Name
 * @param bt-文件内容
 * @param filePath-文件路径
 * @param contentType-文件类型
 */
public static String uploadFile(String s3Name, byte[] bt, String filePath, String contentType, GroupGrantee groupGrantee, Permission permission) {
    InputStream is = new ByteArrayInputStream(bt);
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentLength(bt.length);
    if (contentType != null)
        metadata.setContentType(contentType);
    AccessControlList acl = new AccessControlList();
    acl.grantPermission(groupGrantee, permission);
    buildClient(s3Name).putObject(new PutObjectRequest(bucketMap.get(s3Name).get("bucket"), filePath, is, metadata).withAccessControlList(acl));
    return bucketMap.get(s3Name).get("endpoint") + "/" + bucketMap.get(s3Name).get("bucket") + "/" + filePath;
}
Also used : AccessControlList(com.amazonaws.services.s3.model.AccessControlList) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 2 with GroupGrantee

use of com.amazonaws.services.s3.model.GroupGrantee in project alluxio by Alluxio.

the class S3AUtilsTest method translateAuthenticatedUserWritePermission.

@Test
public void translateAuthenticatedUserWritePermission() {
    GroupGrantee authenticatedUsersGrantee = GroupGrantee.AuthenticatedUsers;
    mAcl.grantPermission(authenticatedUsersGrantee, Permission.Write);
    Assert.assertEquals((short) 0200, S3AUtils.translateBucketAcl(mAcl, ID));
    Assert.assertEquals((short) 0200, S3AUtils.translateBucketAcl(mAcl, OTHER_ID));
}
Also used : GroupGrantee(com.amazonaws.services.s3.model.GroupGrantee) Test(org.junit.Test)

Example 3 with GroupGrantee

use of com.amazonaws.services.s3.model.GroupGrantee in project alluxio by Alluxio.

the class S3AUtilsTest method translateEveryoneFullPermission.

@Test
public void translateEveryoneFullPermission() {
    GroupGrantee allUsersGrantee = GroupGrantee.AllUsers;
    mAcl.grantPermission(allUsersGrantee, Permission.FullControl);
    Assert.assertEquals((short) 0700, S3AUtils.translateBucketAcl(mAcl, ID));
    Assert.assertEquals((short) 0700, S3AUtils.translateBucketAcl(mAcl, OTHER_ID));
}
Also used : GroupGrantee(com.amazonaws.services.s3.model.GroupGrantee) Test(org.junit.Test)

Example 4 with GroupGrantee

use of com.amazonaws.services.s3.model.GroupGrantee in project alluxio by Alluxio.

the class S3AUtilsTest method translateAuthenticatedUserReadPermission.

@Test
public void translateAuthenticatedUserReadPermission() {
    GroupGrantee authenticatedUsersGrantee = GroupGrantee.AuthenticatedUsers;
    mAcl.grantPermission(authenticatedUsersGrantee, Permission.Read);
    Assert.assertEquals((short) 0500, S3AUtils.translateBucketAcl(mAcl, ID));
    Assert.assertEquals((short) 0500, S3AUtils.translateBucketAcl(mAcl, OTHER_ID));
}
Also used : GroupGrantee(com.amazonaws.services.s3.model.GroupGrantee) Test(org.junit.Test)

Example 5 with GroupGrantee

use of com.amazonaws.services.s3.model.GroupGrantee in project alluxio by Alluxio.

the class S3AUtilsTest method translateEveryoneWritePermission.

@Test
public void translateEveryoneWritePermission() {
    GroupGrantee allUsersGrantee = GroupGrantee.AllUsers;
    mAcl.grantPermission(allUsersGrantee, Permission.Write);
    Assert.assertEquals((short) 0200, S3AUtils.translateBucketAcl(mAcl, ID));
    Assert.assertEquals((short) 0200, S3AUtils.translateBucketAcl(mAcl, OTHER_ID));
}
Also used : GroupGrantee(com.amazonaws.services.s3.model.GroupGrantee) Test(org.junit.Test)

Aggregations

GroupGrantee (com.amazonaws.services.s3.model.GroupGrantee)6 Test (org.junit.Test)6 AccessControlList (com.amazonaws.services.s3.model.AccessControlList)1 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)1 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1