本文整理汇总了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);
}