當前位置: 首頁>>代碼示例>>Java>>正文


Java CannedAccessControlList類代碼示例

本文整理匯總了Java中com.amazonaws.services.s3.model.CannedAccessControlList的典型用法代碼示例。如果您正苦於以下問題:Java CannedAccessControlList類的具體用法?Java CannedAccessControlList怎麽用?Java CannedAccessControlList使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CannedAccessControlList類屬於com.amazonaws.services.s3.model包,在下文中一共展示了CannedAccessControlList類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: uploadFile

import com.amazonaws.services.s3.model.CannedAccessControlList; //導入依賴的package包/類
/**
 * Upload a file which is in the assets bucket.
 * 
 * @param fileName File name
 * @param file File
 * @param contentType Content type for file
 * @return
 */
public static boolean uploadFile(String fileName, File file, String contentType) {
    try {
        if (S3Module.amazonS3 != null) {
            String bucket = S3Module.s3Bucket;
            ObjectMetadata metaData = new ObjectMetadata();
            if (contentType != null) {
                metaData.setContentType(contentType);
            }
            PutObjectRequest putObj = new PutObjectRequest(bucket,
                    fileName, file);
            putObj.setMetadata(metaData);
            putObj.withCannedAcl(CannedAccessControlList.PublicRead);
            S3Module.amazonS3.putObject(putObj);
            return true;
        } else {
            Logger.error("Could not save because amazonS3 was null");
            return false;
        }
    } catch (Exception e) {
        Logger.error("S3 Upload -" + e.getMessage());
        return false;
    }
}
 
開發者ID:webinerds,項目名稱:s3-proxy-chunk-upload,代碼行數:32,代碼來源:AssetsS3.java

示例2: uploadToS3

import com.amazonaws.services.s3.model.CannedAccessControlList; //導入依賴的package包/類
public static void uploadToS3() {
    // upload to s3 bucket
    AWSCredentials awsCredentials = SkillConfig.getAWSCredentials();
    AmazonS3Client s3Client = awsCredentials != null ? new AmazonS3Client(awsCredentials) : new AmazonS3Client();

    File folder = new File("c:/temp/morse/" + DOT + "/mp3/");
    File[] listOfFiles = folder.listFiles();

    for (File file : listOfFiles) {
        if (file.isFile()) {
            if (!s3Client.doesObjectExist("morseskill", DOT + "/" + file.getName())) {
                PutObjectRequest s3Put = new PutObjectRequest("morseskill", DOT + "/" + file.getName(), file).withCannedAcl(CannedAccessControlList.PublicRead);
                s3Client.putObject(s3Put);
                System.out.println("Upload complete: " + file.getName());
            }
            else {
                System.out.println("Skip as " + file.getName() + " already exists.");
            }
        }
    }
}
 
開發者ID:KayLerch,項目名稱:alexa-morser-coder-skill,代碼行數:22,代碼來源:AudioUtils.java

示例3: createShortUrl

import com.amazonaws.services.s3.model.CannedAccessControlList; //導入依賴的package包/類
/**
 * The method creates a short URL code for the given url
 * 
 * @param url
 * @return
 */
public ShortUrl createShortUrl(String url, String code) {

	logger.info("storing the url {} in the bucket {}", url, this.bucket);
	// Create the link for the short code
	if (code == null) {
		code = getObjectCode();
	}
	String loadFile = redirectFile.replace("REPLACE", url);
	byte[] fileContentBytes = loadFile.getBytes(StandardCharsets.UTF_8);
	InputStream fileInputStream = new ByteArrayInputStream(fileContentBytes);
	ObjectMetadata metadata = new ObjectMetadata();
	metadata.setContentType("text/html");
	metadata.addUserMetadata("url", url);
	metadata.setContentLength(fileContentBytes.length);
	PutObjectRequest putObjectRequest = new PutObjectRequest(this.bucket, code, fileInputStream, metadata)
			.withCannedAcl(CannedAccessControlList.PublicRead);
	this.s3Client.putObject(putObjectRequest);
	createDummyRecord(url, code);
	return new ShortUrl(url, code);
}
 
開發者ID:weblegit,項目名稱:urlshortner,代碼行數:27,代碼來源:UrlShortnerService.java

示例4: setBucketAcl

import com.amazonaws.services.s3.model.CannedAccessControlList; //導入依賴的package包/類
@Override
public void setBucketAcl(SetBucketAclRequest setBucketAclRequest)
        throws SdkClientException, AmazonServiceException {
    setBucketAclRequest = beforeClientExecution(setBucketAclRequest);

    String bucketName = setBucketAclRequest.getBucketName();
    rejectNull(bucketName, "The bucket name parameter must be specified when setting a bucket's ACL");

    AccessControlList acl = setBucketAclRequest.getAcl();
    CannedAccessControlList cannedAcl = setBucketAclRequest.getCannedAcl();

    if (acl == null && cannedAcl == null) {
        throw new IllegalArgumentException(
                "The ACL parameter must be specified when setting a bucket's ACL");
    }
    if (acl != null && cannedAcl != null) {
        throw new IllegalArgumentException(
                "Only one of the acl and cannedAcl parameter can be specified, not both.");
    }

    if (acl != null) {
        setAcl(bucketName, null, null, acl, false, setBucketAclRequest);
    } else {
        setAcl(bucketName, null, null, cannedAcl, false, setBucketAclRequest);
    }
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:27,代碼來源:AmazonS3Client.java

示例5: uploadImageToS3

import com.amazonaws.services.s3.model.CannedAccessControlList; //導入依賴的package包/類
public String uploadImageToS3(final BufferedImage image, final String fileKey) throws IOException {
    ByteArrayInputStream bis = null;
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        ImageIO.write(image, "png", bos);
        final byte[] bImageData = bos.toByteArray();
        bis = new ByteArrayInputStream(bImageData);
        // upload to s3 bucket
        final PutObjectRequest s3Put = new PutObjectRequest(bucket, fileKey, bis, null).withCannedAcl(CannedAccessControlList.PublicRead);
        s3Client.putObject(s3Put);
        return getS3Url(fileKey);
    } finally {
        try {
            bos.close();
            if (bis != null) bis.close();
        }
        catch(IOException e) {
            logger.severe("Error while closing stream for writing an image for " + fileKey + " caused by " + e.getMessage());
        }
    }
}
 
開發者ID:KayLerch,項目名稱:alexa-morse-coder,代碼行數:22,代碼來源:S3Utils.java

示例6: uploadFileToS3

import com.amazonaws.services.s3.model.CannedAccessControlList; //導入依賴的package包/類
protected static String uploadFileToS3(BufferedImage image, String word, Boolean codeOnly) throws IOException {
    ByteArrayInputStream bis = null;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        String bucket = SkillConfig.getS3BucketName();
        String fileKey = getFileKey(word, codeOnly);
        ImageIO.write(image, "png", bos);
        byte[] bImageData = bos.toByteArray();
        bis = new ByteArrayInputStream(bImageData);
        // upload to s3 bucket
        AWSCredentials awsCredentials = SkillConfig.getAWSCredentials();
        AmazonS3Client s3Client = awsCredentials != null ? new AmazonS3Client(awsCredentials) : new AmazonS3Client();
        PutObjectRequest s3Put = new PutObjectRequest(bucket, fileKey, bis, null).withCannedAcl(CannedAccessControlList.PublicRead);
        s3Client.putObject(s3Put);
        return getS3Url(word, codeOnly);
    } finally {
        bos.close();
        if (bis != null) bis.close();
    }
}
 
開發者ID:KayLerch,項目名稱:alexa-morser-coder-skill,代碼行數:21,代碼來源:ImageUtils.java

示例7: uploadObject

import com.amazonaws.services.s3.model.CannedAccessControlList; //導入依賴的package包/類
@Override
public PutObjectResult uploadObject(final String bucketName, final String fileName, final InputStream inputStream,
		final CannedAccessControlList cannedAcl) throws AmazonClientException, AmazonServiceException, IOException {
	LOGGER.info("uploadObject invoked, bucketName: {} , fileName: {}, cannedAccessControlList: {}", bucketName, fileName, cannedAcl);
	File tempFile = null;
	PutObjectRequest putObjectRequest = null;
	PutObjectResult uploadResult = null;
	try {
		// Create temporary file from stream to avoid 'out of memory' exception
		tempFile = AWSUtil.createTempFileFromStream(inputStream);
		putObjectRequest = new PutObjectRequest(bucketName, fileName, tempFile).withCannedAcl(cannedAcl);
		uploadResult = uploadObject(putObjectRequest);
	} finally {
		AWSUtil.deleteTempFile(tempFile); // Delete the temporary file once uploaded
	}
	return uploadResult;
}
 
開發者ID:abhinavmishra14,項目名稱:aws-s3-utils,代碼行數:18,代碼來源:AwsS3IamServiceImpl.java

示例8: createDirectory

import com.amazonaws.services.s3.model.CannedAccessControlList; //導入依賴的package包/類
@Override
public PutObjectResult createDirectory(final String bucketName, final String dirName,
		final boolean isPublicAccessible) throws AmazonClientException, AmazonServiceException {
	LOGGER.info("createDirectory invoked, bucketName: {}, dirName: {} and isPublicAccessible: {}", bucketName, dirName, isPublicAccessible);
	final ObjectMetadata metadata = new ObjectMetadata();
	metadata.setContentLength(0);
	// Create empty content,since creating empty folder needs an empty content
	final InputStream emptyContent = new ByteArrayInputStream(new byte[0]);
	// Create a PutObjectRequest passing the directory name suffixed by '/'
	final PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, dirName + AWSUtilConstants.SEPARATOR,
			emptyContent, metadata);
	if(isPublicAccessible){
	  putObjectRequest.setCannedAcl(CannedAccessControlList.PublicRead);
	}
	return s3client.putObject(putObjectRequest);
}
 
開發者ID:abhinavmishra14,項目名稱:aws-s3-utils,代碼行數:17,代碼來源:AwsS3IamServiceImpl.java

示例9: uploadToS3

import com.amazonaws.services.s3.model.CannedAccessControlList; //導入依賴的package包/類
public static void uploadToS3(TransferManager transferManager, final File file, final FileProgressListener fileProgressListener) throws InterruptedException {
    PutObjectRequest putObjectRequest = new PutObjectRequest("car-classifieds", file.getName(), file)
            .withCannedAcl(CannedAccessControlList.PublicRead);
    final Upload upload = transferManager.upload(putObjectRequest);
    upload.addProgressListener(new ProgressListener() {
        @Override
        public void progressChanged(ProgressEvent progressEvent) {
            fileProgressListener.onProgressChanged(progressEvent.getBytesTransferred());
            if (progressEvent.getEventCode() == ProgressEvent.COMPLETED_EVENT_CODE) {
                fileProgressListener.onCompleteUpload();
            }
            if (progressEvent.getEventCode() == com.amazonaws.event.ProgressEvent.STARTED_EVENT_CODE) {
                fileProgressListener.onStartUpload();
            }
            if (progressEvent.getEventCode() == com.amazonaws.event.ProgressEvent.FAILED_EVENT_CODE) {
                fileProgressListener.onFailedUpload();
            }
        }
    });
}
 
開發者ID:pamu,項目名稱:upman,代碼行數:21,代碼來源:S3Uploader.java

示例10: execute

import com.amazonaws.services.s3.model.CannedAccessControlList; //導入依賴的package包/類
public cfData execute( cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException{
	
AmazonKey amazonKey	= getAmazonKey(_session, argStruct);
AmazonS3 s3Client		= getAmazonS3(amazonKey);

	String bucket			= getNamedStringParam(argStruct, "bucket", null );
	String key				= getNamedStringParam(argStruct, "key", null );
	
if ( key != null && key.charAt( 0 ) == '/' )
	key	= key.substring(1);

	CannedAccessControlList	acl	= amazonKey.getAmazonCannedAcl( getNamedStringParam(argStruct, "acl", null ) );
	
try {
		s3Client.setObjectAcl(bucket, key, acl);
} catch (Exception e) {
	throwException(_session, "AmazonS3: " + e.getMessage() );
}
return cfBooleanData.TRUE;
}
 
開發者ID:OpenBD,項目名稱:openbd-core,代碼行數:21,代碼來源:SetAcl.java

示例11: execute

import com.amazonaws.services.s3.model.CannedAccessControlList; //導入依賴的package包/類
public cfData execute( cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException{
	
AmazonKey amazonKey	= getAmazonKey(_session, argStruct);
AmazonS3 s3Client		= getAmazonS3(amazonKey);
	String bucket				= getNamedStringParam(argStruct, "bucket", null );
	
	CannedAccessControlList	acl	= amazonKey.getAmazonCannedAcl( getNamedStringParam(argStruct, "acl", null ) );
	
try {
		s3Client.setBucketAcl(bucket, acl);
} catch (Exception e) {
	throwException(_session, "AmazonS3: " + e.getMessage() );
}

return cfBooleanData.TRUE;
}
 
開發者ID:OpenBD,項目名稱:openbd-core,代碼行數:17,代碼來源:SetBucketAcl.java

示例12: getAmazonCannedAcl

import com.amazonaws.services.s3.model.CannedAccessControlList; //導入依賴的package包/類
/**
 * private | public-read | public-read-write | authenticated-read | bucket-owner-read | bucket-owner-full-control | log-delivery-write
 *
 * @param acl
 * @return
 */
public CannedAccessControlList getAmazonCannedAcl(String acl) {
	if (acl.equalsIgnoreCase("private"))
		return CannedAccessControlList.Private;
	else if (acl.equalsIgnoreCase("public-read") || acl.equalsIgnoreCase("publicread"))
		return CannedAccessControlList.PublicRead;
	else if (acl.equalsIgnoreCase("public-read-write") || acl.equalsIgnoreCase("publicreadwrite"))
		return CannedAccessControlList.PublicReadWrite;
	else if (acl.equalsIgnoreCase("authenticated-read") || acl.equalsIgnoreCase("authenticatedread"))
		return CannedAccessControlList.AuthenticatedRead;
	else if (acl.equalsIgnoreCase("bucket-owner-read") || acl.equalsIgnoreCase("bucketownerread"))
		return CannedAccessControlList.BucketOwnerRead;
	else if (acl.equalsIgnoreCase("bucket-owner-full-control") || acl.equalsIgnoreCase("bucketownerfullcontrol"))
		return CannedAccessControlList.BucketOwnerFullControl;
	else if (acl.equalsIgnoreCase("log-delivery-write") || acl.equalsIgnoreCase("logdeliverywrite"))
		return CannedAccessControlList.LogDeliveryWrite;
	else
		return CannedAccessControlList.Private;
}
 
開發者ID:OpenBD,項目名稱:openbd-core,代碼行數:25,代碼來源:AmazonKey.java

示例13: testHttpClient

import com.amazonaws.services.s3.model.CannedAccessControlList; //導入依賴的package包/類
@Test
public void testHttpClient() throws Exception {
    String blobName = "blob-name";
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentLength(BYTE_SOURCE.size());
    client.putObject(containerName, blobName, BYTE_SOURCE.openStream(),
            metadata);

    if (Quirks.NO_BLOB_ACCESS_CONTROL.contains(blobStoreType)) {
        client.setBucketAcl(containerName,
                CannedAccessControlList.PublicRead);
    } else {
        client.setObjectAcl(containerName, blobName,
                CannedAccessControlList.PublicRead);
    }

    HttpClient httpClient = context.utils().http();
    URI uri = new URI(s3Endpoint.getScheme(), s3Endpoint.getUserInfo(),
            s3Endpoint.getHost(), s3Proxy.getSecurePort(),
            servicePath + "/" + containerName + "/" + blobName,
            /*query=*/ null, /*fragment=*/ null);
    try (InputStream actual = httpClient.get(uri);
         InputStream expected = BYTE_SOURCE.openStream()) {
        assertThat(actual).hasContentEqualTo(expected);
    }
}
 
開發者ID:gaul,項目名稱:s3proxy,代碼行數:27,代碼來源:AwsSdkTest.java

示例14: publicEntity

import com.amazonaws.services.s3.model.CannedAccessControlList; //導入依賴的package包/類
@Override
public boolean publicEntity(String bucketName, String keyName) {
    LOG.info("Sets the CannedAccessControlList for the specified object "
            + keyName
            + " in Amazon S3 using one of the pre-configured CannedAccessControlLists");
    
    try {
    	amazonS3Client.setObjectAcl(bucketName, keyName, CannedAccessControlList.PublicRead);
    	return true;
    } catch (AmazonServiceException ase) {
        LOG.warn(ase.getMessage(), ase);
    } catch (AmazonClientException ace) {
        LOG.warn(ace.getMessage(), ace);
    }
    return false;
}
 
開發者ID:dgks0n,項目名稱:milton-aws,代碼行數:17,代碼來源:AmazonS3ManagerImpl.java

示例15: uploadTextAsFile

import com.amazonaws.services.s3.model.CannedAccessControlList; //導入依賴的package包/類
private boolean uploadTextAsFile(String key, String contents){
	try{
		byte[] bytes = contents.getBytes("UTF-8");
		InputStream is = new ByteArrayInputStream(bytes);

		String bucket = "s3.staticvoidgames.com";


		ObjectMetadata meta = new ObjectMetadata();
		meta.setContentLength(bytes.length);
		meta.setContentType("text/html");

		String awsAccessKey = env.getProperty("aws.accessKey");
		String awsSecretKey = env.getProperty("aws.secretKey");
		AmazonS3 s3 = new AmazonS3Client(new BasicAWSCredentials(awsAccessKey, awsSecretKey));

		s3.putObject(bucket, key, is, meta);
		s3.setObjectAcl(bucket, key, CannedAccessControlList.PublicRead);
	}
	catch(UnsupportedEncodingException e){
		e.printStackTrace();
		return false;
	}

	return true;
}
 
開發者ID:KevinWorkman,項目名稱:StaticVoidGames,代碼行數:27,代碼來源:EditGameController.java


注:本文中的com.amazonaws.services.s3.model.CannedAccessControlList類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。