本文整理匯總了Java中com.amazonaws.services.s3.model.PutObjectRequest.withCannedAcl方法的典型用法代碼示例。如果您正苦於以下問題:Java PutObjectRequest.withCannedAcl方法的具體用法?Java PutObjectRequest.withCannedAcl怎麽用?Java PutObjectRequest.withCannedAcl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.amazonaws.services.s3.model.PutObjectRequest
的用法示例。
在下文中一共展示了PutObjectRequest.withCannedAcl方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: uploadFile
import com.amazonaws.services.s3.model.PutObjectRequest; //導入方法依賴的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;
}
}
示例2: putFile
import com.amazonaws.services.s3.model.PutObjectRequest; //導入方法依賴的package包/類
private void putFile(Path from, String key)
{
PutObjectRequest request = new PutObjectRequest(bucket, key, from.toFile());
if (cannedAccessControlListOptional.isPresent()) {
request.withCannedAcl(cannedAccessControlListOptional.get());
}
client.putObject(request);
}