本文整理匯總了Java中com.amazonaws.services.s3.model.PutObjectRequest.setCannedAcl方法的典型用法代碼示例。如果您正苦於以下問題:Java PutObjectRequest.setCannedAcl方法的具體用法?Java PutObjectRequest.setCannedAcl怎麽用?Java PutObjectRequest.setCannedAcl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.amazonaws.services.s3.model.PutObjectRequest
的用法示例。
在下文中一共展示了PutObjectRequest.setCannedAcl方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createEmptyObject
import com.amazonaws.services.s3.model.PutObjectRequest; //導入方法依賴的package包/類
private void createEmptyObject(final String bucketName, final String objectName)
throws AmazonClientException, AmazonServiceException {
final InputStream im = new InputStream() {
@Override
public int read() throws IOException {
return -1;
}
};
final ObjectMetadata om = new ObjectMetadata();
om.setContentLength(0L);
if (StringUtils.isNotBlank(serverSideEncryptionAlgorithm)) {
om.setServerSideEncryption(serverSideEncryptionAlgorithm);
}
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, im, om);
putObjectRequest.setCannedAcl(cannedACL);
s3.putObject(putObjectRequest);
statistics.incrementWriteOps(1);
}
示例2: createEmptyObject
import com.amazonaws.services.s3.model.PutObjectRequest; //導入方法依賴的package包/類
private void createEmptyObject(final String bucketName, final String objectName)
throws AmazonClientException, AmazonServiceException {
final InputStream im = new InputStream() {
@Override
public int read() throws IOException {
return -1;
}
};
final ObjectMetadata om = new ObjectMetadata();
om.setContentLength(0L);
if (StringUtils.isNotBlank(serverSideEncryptionAlgorithm)) {
om.setSSEAlgorithm(serverSideEncryptionAlgorithm);
}
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, im, om);
putObjectRequest.setCannedAcl(cannedACL);
s3.putObject(putObjectRequest);
statistics.incrementWriteOps(1);
}
示例3: createDirectory
import com.amazonaws.services.s3.model.PutObjectRequest; //導入方法依賴的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);
}
示例4: run
import com.amazonaws.services.s3.model.PutObjectRequest; //導入方法依賴的package包/類
@Override
public void run() {
ObjectMetadata meta_data = new ObjectMetadata();
if (p_content_type != null)
meta_data.setContentType(p_content_type);
meta_data.setContentLength(p_size);
PutObjectRequest putObjectRequest = new PutObjectRequest(p_bucket_name, p_s3_key, p_file_stream, meta_data);
putObjectRequest.setCannedAcl(CannedAccessControlList.PublicRead);
PutObjectResult res = s3Client.putObject(putObjectRequest);
}
示例5: putObject
import com.amazonaws.services.s3.model.PutObjectRequest; //導入方法依賴的package包/類
private void putObject() throws IOException {
if (LOG.isDebugEnabled()) {
LOG.debug("Executing regular upload for bucket '{}' key '{}'", bucket,
key);
}
final ObjectMetadata om = createDefaultMetadata();
om.setContentLength(buffer.size());
final PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key,
new ByteArrayInputStream(buffer.toByteArray()), om);
putObjectRequest.setCannedAcl(cannedACL);
putObjectRequest.setGeneralProgressListener(progressListener);
ListenableFuture<PutObjectResult> putObjectResult =
executorService.submit(new Callable<PutObjectResult>() {
@Override
public PutObjectResult call() throws Exception {
return client.putObject(putObjectRequest);
}
});
//wait for completion
try {
putObjectResult.get();
} catch (InterruptedException ie) {
LOG.warn("Interrupted object upload:" + ie, ie);
Thread.currentThread().interrupt();
} catch (ExecutionException ee) {
throw new IOException("Regular upload failed", ee.getCause());
}
}
示例6: saveImageToAWS
import com.amazonaws.services.s3.model.PutObjectRequest; //導入方法依賴的package包/類
void saveImageToAWS(String fileName, File file, String sessionId, String index) {
PutObjectRequest request = new PutObjectRequest(s3Name, fileName, file);
request.setCannedAcl(CannedAccessControlList.PublicRead);
getS3().putObject(request);
// Save the information to DB
storeNewImageOnDynamo(sessionId, index, s3Endpoint + fileName);
}
示例7: copyJsonDataToS3
import com.amazonaws.services.s3.model.PutObjectRequest; //導入方法依賴的package包/類
private void copyJsonDataToS3(String keyName, String jsonToCopy) throws Exception {
logger.log("About to copy cached json data to S3");
try {
logger.log("Uploading json data to S3 bucket: " + websiteBucketName + " and key: " + keyName
+ ".json");
byte[] jsonAsBytes = jsonToCopy.getBytes(StandardCharsets.UTF_8);
ByteArrayInputStream jsonAsStream = new ByteArrayInputStream(jsonAsBytes);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(jsonAsBytes.length);
metadata.setContentType("application/json");
// Direct caches not to satisfy future requests with this data without
// revalidation.
if (keyName.contains("famousplayers")) {
// Famousplayers list is good for a year
metadata.setCacheControl("max-age=31536000");
} else {
metadata.setCacheControl("no-cache, must-revalidate");
}
PutObjectRequest putObjectRequest = new PutObjectRequest(websiteBucketName,
keyName + ".json", jsonAsStream, metadata);
// Data must be public so it can be served from the website
putObjectRequest.setCannedAcl(CannedAccessControlList.PublicRead);
IS3TransferManager transferManager = getS3TransferManager();
TransferUtils.waitForS3Transfer(transferManager.upload(putObjectRequest), logger);
logger.log("Uploaded cached json data to S3 bucket");
} catch (AmazonServiceException ase) {
ExceptionUtils.logAmazonServiceException(ase, logger);
throw new Exception("Exception caught while copying json data to S3");
} catch (AmazonClientException ace) {
ExceptionUtils.logAmazonClientException(ace, logger);
throw new Exception("Exception caught while copying json data to S3");
} catch (InterruptedException e) {
logger.log("Caught interrupted exception: ");
logger.log("Error Message: " + e.getMessage());
throw new Exception("Exception caught while copying json data to S3");
}
}
示例8: uploadFileAsync
import com.amazonaws.services.s3.model.PutObjectRequest; //導入方法依賴的package包/類
@Override
public Upload uploadFileAsync(final String bucketName, final String fileName, final File fileObj,
final boolean isPublicAccessible) throws AmazonClientException, AmazonServiceException, IOException {
LOGGER.info("uploadObjectAsync invoked, bucketName: {} , fileName: {} and isPublicAccessible: {}", bucketName, fileName, isPublicAccessible);
final PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, fileName, fileObj);
if(isPublicAccessible){
putObjectRequest.setCannedAcl(CannedAccessControlList.PublicRead);
}
final TransferManager transferMgr = new TransferManager(s3client);
return transferMgr.upload(putObjectRequest);
}
示例9: close
import com.amazonaws.services.s3.model.PutObjectRequest; //導入方法依賴的package包/類
@Override
public synchronized void close() throws IOException {
if (closed) {
return;
}
backupStream.close();
if (LOG.isDebugEnabled()) {
LOG.debug("OutputStream for key '" + key + "' closed. Now beginning upload");
LOG.debug("Minimum upload part size: " + partSize + " threshold " + partSizeThreshold);
}
try {
final ObjectMetadata om = new ObjectMetadata();
if (StringUtils.isNotBlank(serverSideEncryptionAlgorithm)) {
om.setServerSideEncryption(serverSideEncryptionAlgorithm);
}
PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, backupFile);
putObjectRequest.setCannedAcl(cannedACL);
putObjectRequest.setMetadata(om);
Upload upload = transfers.upload(putObjectRequest);
ProgressableProgressListener listener =
new ProgressableProgressListener(upload, progress, statistics);
upload.addProgressListener(listener);
upload.waitForUploadResult();
long delta = upload.getProgress().getBytesTransferred() - listener.getLastBytesTransferred();
if (statistics != null && delta != 0) {
if (LOG.isDebugEnabled()) {
LOG.debug("S3A write delta changed after finished: " + delta + " bytes");
}
statistics.incrementBytesWritten(delta);
}
// This will delete unnecessary fake parent directories
fs.finishedWrite(key);
} catch (InterruptedException e) {
throw new IOException(e);
} finally {
if (!backupFile.delete()) {
LOG.warn("Could not delete temporary s3a file: {}", backupFile);
}
super.close();
closed = true;
}
if (LOG.isDebugEnabled()) {
LOG.debug("OutputStream for key '" + key + "' upload complete");
}
}
示例10: copyFromLocalFile
import com.amazonaws.services.s3.model.PutObjectRequest; //導入方法依賴的package包/類
/**
* The src file is on the local disk. Add it to FS at
* the given dst name.
*
* This version doesn't need to create a temporary file to calculate the md5.
* Sadly this doesn't seem to be used by the shell cp :(
*
* delSrc indicates if the source should be removed
* @param delSrc whether to delete the src
* @param overwrite whether to overwrite an existing file
* @param src path
* @param dst path
*/
@Override
public void copyFromLocalFile(boolean delSrc, boolean overwrite, Path src,
Path dst) throws IOException {
String key = pathToKey(dst);
if (!overwrite && exists(dst)) {
throw new IOException(dst + " already exists");
}
if (LOG.isDebugEnabled()) {
LOG.debug("Copying local file from " + src + " to " + dst);
}
// Since we have a local file, we don't need to stream into a temporary file
LocalFileSystem local = getLocal(getConf());
File srcfile = local.pathToFile(src);
final ObjectMetadata om = new ObjectMetadata();
if (StringUtils.isNotBlank(serverSideEncryptionAlgorithm)) {
om.setServerSideEncryption(serverSideEncryptionAlgorithm);
}
PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, srcfile);
putObjectRequest.setCannedAcl(cannedACL);
putObjectRequest.setMetadata(om);
ProgressListener progressListener = new ProgressListener() {
public void progressChanged(ProgressEvent progressEvent) {
switch (progressEvent.getEventCode()) {
case ProgressEvent.PART_COMPLETED_EVENT_CODE:
statistics.incrementWriteOps(1);
break;
default:
break;
}
}
};
Upload up = transfers.upload(putObjectRequest);
up.addProgressListener(progressListener);
try {
up.waitForUploadResult();
statistics.incrementWriteOps(1);
} catch (InterruptedException e) {
throw new IOException("Got interrupted, cancelling");
}
// This will delete unnecessary fake parent directories
finishedWrite(key);
if (delSrc) {
local.delete(src, false);
}
}
示例11: close
import com.amazonaws.services.s3.model.PutObjectRequest; //導入方法依賴的package包/類
@Override
public synchronized void close() throws IOException {
if (closed) {
return;
}
backupStream.close();
if (LOG.isDebugEnabled()) {
LOG.debug("OutputStream for key '" + key + "' closed. Now beginning upload");
LOG.debug("Minimum upload part size: " + partSize + " threshold " + partSizeThreshold);
}
try {
final ObjectMetadata om = new ObjectMetadata();
if (StringUtils.isNotBlank(serverSideEncryptionAlgorithm)) {
om.setSSEAlgorithm(serverSideEncryptionAlgorithm);
}
PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, backupFile);
putObjectRequest.setCannedAcl(cannedACL);
putObjectRequest.setMetadata(om);
Upload upload = transfers.upload(putObjectRequest);
ProgressableProgressListener listener =
new ProgressableProgressListener(upload, progress, statistics);
upload.addProgressListener(listener);
upload.waitForUploadResult();
long delta = upload.getProgress().getBytesTransferred() - listener.getLastBytesTransferred();
if (statistics != null && delta != 0) {
if (LOG.isDebugEnabled()) {
LOG.debug("S3A write delta changed after finished: " + delta + " bytes");
}
statistics.incrementBytesWritten(delta);
}
// This will delete unnecessary fake parent directories
fs.finishedWrite(key);
} catch (InterruptedException e) {
throw new IOException(e);
} finally {
if (!backupFile.delete()) {
LOG.warn("Could not delete temporary s3a file: {}", backupFile);
}
super.close();
closed = true;
}
if (LOG.isDebugEnabled()) {
LOG.debug("OutputStream for key '" + key + "' upload complete");
}
}
示例12: copyFromLocalFile
import com.amazonaws.services.s3.model.PutObjectRequest; //導入方法依賴的package包/類
/**
* The src file is on the local disk. Add it to FS at
* the given dst name.
*
* This version doesn't need to create a temporary file to calculate the md5.
* Sadly this doesn't seem to be used by the shell cp :(
*
* delSrc indicates if the source should be removed
* @param delSrc whether to delete the src
* @param overwrite whether to overwrite an existing file
* @param src path
* @param dst path
*/
@Override
public void copyFromLocalFile(boolean delSrc, boolean overwrite, Path src,
Path dst) throws IOException {
String key = pathToKey(dst);
if (!overwrite && exists(dst)) {
throw new IOException(dst + " already exists");
}
if (LOG.isDebugEnabled()) {
LOG.debug("Copying local file from " + src + " to " + dst);
}
// Since we have a local file, we don't need to stream into a temporary file
LocalFileSystem local = getLocal(getConf());
File srcfile = local.pathToFile(src);
final ObjectMetadata om = new ObjectMetadata();
if (StringUtils.isNotBlank(serverSideEncryptionAlgorithm)) {
om.setSSEAlgorithm(serverSideEncryptionAlgorithm);
}
PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, srcfile);
putObjectRequest.setCannedAcl(cannedACL);
putObjectRequest.setMetadata(om);
ProgressListener progressListener = new ProgressListener() {
public void progressChanged(ProgressEvent progressEvent) {
switch (progressEvent.getEventType()) {
case TRANSFER_PART_COMPLETED_EVENT:
statistics.incrementWriteOps(1);
break;
default:
break;
}
}
};
Upload up = transfers.upload(putObjectRequest);
up.addProgressListener(progressListener);
try {
up.waitForUploadResult();
statistics.incrementWriteOps(1);
} catch (InterruptedException e) {
throw new IOException("Got interrupted, cancelling");
}
// This will delete unnecessary fake parent directories
finishedWrite(key);
if (delSrc) {
local.delete(src, false);
}
}
示例13: storeFile
import com.amazonaws.services.s3.model.PutObjectRequest; //導入方法依賴的package包/類
@Override
public void storeFile(final FileType fileType,
final PersistentFileMetadata metadata,
final InputStream inputStream) throws IOException {
final String bucketName = fileType.resolveAwsBucketName(awsConfigProperties);
final String objectKey = fileType.resolveAwsBucketKey(metadata);
if (!StringUtils.hasText(bucketName)) {
throw new IllegalStateException("Bucket name is not configured for fileType=" + fileType);
}
// Store S3 bucket and key embedded as resource URL
metadata.setResourceUrl(S3Util.createResourceURL(bucketName, objectKey));
final ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(Objects.requireNonNull(metadata.getContentSize()));
objectMetadata.setContentType(Objects.requireNonNull(metadata.getContentType()));
if (metadata.getMd5Hash() != null) {
// Use MD5 to verify uploaded file
objectMetadata.setContentMD5(Base64.encodeAsString(metadata.getMd5Hash().asBytes()));
}
try {
final PutObjectRequest request = new PutObjectRequest(bucketName, objectKey, inputStream, objectMetadata);
request.setCannedAcl(CannedAccessControlList.Private);
final Upload upload = this.transferManager.upload(request);
upload.waitForUploadResult();
} catch (Exception e) {
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
} finally {
inputStream.close();
}
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCompletion(final int status) {
// Remove file if transaction is rolled back
if (status == STATUS_ROLLED_BACK) {
removeInternal(new S3Util.BucketObjectPair(bucketName, objectKey));
}
}
});
}
示例14: copyUpdatedBookingPageToS3
import com.amazonaws.services.s3.model.PutObjectRequest; //導入方法依賴的package包/類
private void copyUpdatedBookingPageToS3(String pageBaseName, String page, String uidSuffix,
boolean usePrefix) throws Exception {
logger.log("About to copy booking page to S3");
String pageBaseNameWithPrefix = usePrefix ? "NoScript/" + pageBaseName : pageBaseName;
try {
logger.log("Uploading booking page to S3 bucket: " + websiteBucketName
+ "s3websitebucketname" + " and key: " + pageBaseNameWithPrefix + uidSuffix + ".html");
byte[] pageAsGzippedBytes = FileUtils.gzip(page.getBytes(StandardCharsets.UTF_8), logger);
ByteArrayInputStream pageAsStream = new ByteArrayInputStream(pageAsGzippedBytes);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(pageAsGzippedBytes.length);
metadata.setContentEncoding("gzip");
metadata.setContentType("text/html");
// Direct caches not to satisfy future requests with this data without
// revalidation.
metadata.setCacheControl("no-cache, must-revalidate");
PutObjectRequest putObjectRequest = new PutObjectRequest(websiteBucketName,
pageBaseNameWithPrefix + uidSuffix + ".html", pageAsStream, metadata);
// Page must be public so it can be served from the website
putObjectRequest.setCannedAcl(CannedAccessControlList.PublicRead);
IS3TransferManager transferManager = getS3TransferManager();
TransferUtils.waitForS3Transfer(transferManager.upload(putObjectRequest), logger);
logger.log("Uploaded booking page to S3 bucket");
if (uidSuffix.equals("")) {
// Nothing to copy - so return
logger.log("UidSuffix is empty - so not creating duplicate page");
return;
}
// N.B. We copy from hashed key to non-hashed (and not vice versa)
// to ensure consistency
logger.log("Copying booking page in S3 bucket: " + websiteBucketName + " and key: "
+ pageBaseNameWithPrefix + ".html");
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(websiteBucketName,
pageBaseNameWithPrefix + uidSuffix + ".html", websiteBucketName, pageBaseNameWithPrefix
+ ".html");
copyObjectRequest.setCannedAccessControlList(CannedAccessControlList.PublicRead);
// N.B. Copied object will get same metadata as the source (e.g. the
// cache-control header etc.)
TransferUtils.waitForS3Transfer(transferManager.copy(copyObjectRequest), logger);
logger.log("Copied booking page successfully in S3");
} catch (AmazonServiceException ase) {
ExceptionUtils.logAmazonServiceException(ase, logger);
throw new Exception("Exception caught while copying booking page to S3");
} catch (AmazonClientException ace) {
ExceptionUtils.logAmazonClientException(ace, logger);
throw new Exception("Exception caught while copying booking page to S3");
} catch (InterruptedException e) {
logger.log("Caught interrupted exception: ");
logger.log("Error Message: " + e.getMessage());
throw new Exception("Exception caught while copying booking page to S3");
}
}
示例15: copyFromLocalFile
import com.amazonaws.services.s3.model.PutObjectRequest; //導入方法依賴的package包/類
/**
* The src file is on the local disk. Add it to FS at
* the given dst name.
*
* This version doesn't need to create a temporary file to calculate the md5.
* Sadly this doesn't seem to be used by the shell cp :(
*
* delSrc indicates if the source should be removed
* @param delSrc whether to delete the src
* @param overwrite whether to overwrite an existing file
* @param src path
* @param dst path
*/
@Override
public void copyFromLocalFile(boolean delSrc, boolean overwrite, Path src,
Path dst) throws IOException {
String key = pathToKey(dst);
if (!overwrite && exists(dst)) {
throw new IOException(dst + " already exists");
}
if (LOG.isDebugEnabled()) {
LOG.debug("Copying local file from " + src + " to " + dst);
}
// Since we have a local file, we don't need to stream into a temporary file
LocalFileSystem local = getLocal(getConf());
File srcfile = local.pathToFile(src);
final ObjectMetadata om = new ObjectMetadata();
if (StringUtils.isNotBlank(serverSideEncryptionAlgorithm)) {
om.setServerSideEncryption(serverSideEncryptionAlgorithm);
}
PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, srcfile);
putObjectRequest.setCannedAcl(cannedACL);
putObjectRequest.setMetadata(om);
ProgressListener progressListener = new ProgressListener() {
public void progressChanged(ProgressEvent progressEvent) {
switch (progressEvent.getEventCode()) {
case ProgressEvent.PART_COMPLETED_EVENT_CODE:
statistics.incrementWriteOps(1);
break;
}
}
};
Upload up = transfers.upload(putObjectRequest);
up.addProgressListener(progressListener);
try {
up.waitForUploadResult();
statistics.incrementWriteOps(1);
} catch (InterruptedException e) {
throw new IOException("Got interrupted, cancelling");
}
// This will delete unnecessary fake parent directories
finishedWrite(key);
if (delSrc) {
local.delete(src, false);
}
}