本文整理汇总了Java中org.jets3t.service.model.S3Object.setAcl方法的典型用法代码示例。如果您正苦于以下问题:Java S3Object.setAcl方法的具体用法?Java S3Object.setAcl怎么用?Java S3Object.setAcl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jets3t.service.model.S3Object
的用法示例。
在下文中一共展示了S3Object.setAcl方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deploy
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
public void deploy(File jarFile) {
String deployBucket = getOrCry("deployBucket");
String deployFilename = getOrCry("deployFilename");
try {
getStorage().getOrCreateBucket(deployBucket);
AccessControlList bucketAcl = getStorage().getBucketAcl(
deployBucket);
bucketAcl.grantPermission(GroupGrantee.ALL_USERS,
Permission.PERMISSION_READ);
S3Object statFileObject = new S3Object(jarFile);
statFileObject.setKey(deployFilename);
statFileObject.setAcl(bucketAcl);
getStorage().putObject(deployBucket, statFileObject);
log.info("File " + jarFile + " now accessible at " + getJarUrl());
} catch (Exception e) {
log.warn("Failed to deploy or set permissions in bucket "
+ deployBucket + ", key " + deployFilename, e);
}
}
示例2: saveImage
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
private void saveImage(String filename, MultipartFile image)
throws ImageUploadException {
try {
AWSCredentials awsCredentials =
new AWSCredentials(s3AccessKey, s3SecretKey);
S3Service s3 = new RestS3Service(awsCredentials);
S3Bucket imageBucket = s3.getBucket("spitterImages");
S3Object imageObject = new S3Object(filename);
imageObject.setDataInputStream(
new ByteArrayInputStream(image.getBytes()));
imageObject.setContentLength(image.getBytes().length);
imageObject.setContentType("image/jpeg");
AccessControlList acl = new AccessControlList();
acl.setOwner(imageBucket.getOwner());
acl.grantPermission(GroupGrantee.ALL_USERS,
Permission.PERMISSION_READ);
imageObject.setAcl(acl);
s3.putObject(imageBucket, imageObject);
} catch (Exception e) {
throw new ImageUploadException("Unable to save image", e);
}
}
示例3: copy
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Override
public Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
if(source.isFile() || source.isPlaceholder()) {
if(null == status.getStorageClass()) {
// Keep same storage class
status.setStorageClass(new S3StorageClassFeature(session).getClass(source));
}
if(Encryption.Algorithm.NONE == status.getEncryption()) {
// Keep encryption setting
status.setEncryption(new S3EncryptionFeature(session).getEncryption(source));
}
if(Acl.EMPTY == status.getAcl()) {
// Apply non standard ACL
try {
status.setAcl(accessControlListFeature.getPermission(source));
}
catch(AccessDeniedException | InteroperabilityException e) {
log.warn(String.format("Ignore failure %s", e.getDetail()));
}
}
final S3Object destination = new S3WriteFeature(session).getDetails(target, status);
destination.setAcl(accessControlListFeature.convert(status.getAcl()));
destination.setBucketName(containerService.getContainer(target).getName());
this.copy(source, destination, status);
}
return target;
}
示例4: upload
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
public static void upload(String sessionId, String name) {
logger.debug("Upload - session id: {} name: {}", sessionId, name);
try {
// find the file
StringBuilder sb = new StringBuilder(recordPath);
sb.append(sessionId);
sb.append('/');
sb.append(name);
sb.append(".flv");
String filePath = sb.toString();
logger.debug("File path: {}", filePath);
File file = new File(filePath);
if (file.exists()) {
S3Service s3Service = new RestS3Service(awsCredentials);
S3Bucket bucket = s3Service.createBucket(bucketName);
S3Object sob = new S3Object(sessionId + "/" + name + ".flv");
// force bucket name
sob.setBucketName(bucketName);
// point at file
sob.setDataInputFile(file);
// set type
sob.setContentType("video/x-flv");
// set auth / acl
sob.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ);
logger.debug("Pre-upload: {}", sob);
sob = s3Service.putObject(bucket, sob);
logger.debug("Post-upload: {}", sob);
} else {
logger.warn("File was not found");
}
file = null;
} catch (S3ServiceException e) {
logger.error("Error during upload", e);
}
}
示例5: uploadFile
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
public static void uploadFile(final File file, final String fileName, final ContentTypeEnum contentType, final boolean rewrite) {
try {
s3Service = new RestS3Service(AWSCREDENTIALS);
AccessControlList bucketAcl = s3Service.getBucketAcl("pubanywhere");
bucketAcl.grantPermission(GroupGrantee.ALL_USERS, Permission.PERMISSION_READ);
pubanywhere = s3Service.getBucket("pubanywhere");
if (pubanywhere != null) {
S3Object object = new S3Object(pubanywhere, file);
object.setContentLength(file.length());
object.setContentType(contentType.getDescricao());
object.setName(fileName);
object.setAcl(bucketAcl);
if (rewrite) {
s3Service.putObject(pubanywhere, object);
} else {
if (!isFileOnAmazon(fileName)) {
s3Service.putObject(pubanywhere, object);
}
}
log.info("Uploading file: " + fileName + " on amazon");
}
} catch (Exception e) {
log.error("Error uploading file: " + fileName, e.getMessage());
}
}
示例6: createObjectForUpload
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
/**
* Prepares a file for upload to a named object in S3, potentially transforming it if
* zipping or encryption is requested.
* <p>
* The file will have the following metadata items added:
* <ul>
* <li>{@link Constants#METADATA_JETS3T_LOCAL_FILE_DATE}: The local file's last modified date
* in ISO 8601 format</li>
* <li><tt>Content-Type</tt> : A content type guessed from the file's extension, or
* {@link Mimetypes#MIMETYPE_BINARY_OCTET_STREAM} if the file is a directory</li>
* <li><tt>Content-Length</tt> : The size of the file</li>
* <li><tt>MD5-Hash</tt> : An MD5 hash of the file's data</li>
* <li>{@link StorageObject#METADATA_HEADER_ORIGINAL_HASH_MD5}: An MD5 hash of the
* original file's data (added if gzipping or encryption is applied)</li>
* </ul>
*
* @param objectKey
* the object key name to use in S3
* @param dataFile
* the file to prepare for upload.
* @param encryptionUtil
* if this variable is null no encryption will be applied, otherwise the provided
* encryption utility object will be used to encrypt the file's data.
* @param gzipFile
* if true the file will be Gzipped.
* @param progressWatcher
* watcher to monitor progress of file transformation and hash generation.
*
* @return
* an S3Object representing the file, or a transformed copy of the file, complete with
* all JetS3t-specific metadata items set and ready for upload to S3.
*
* @throws Exception
* exceptions could include IO failures, gzipping and encryption failures.
*/
public static S3Object createObjectForUpload(String objectKey, File dataFile,
EncryptionUtil encryptionUtil, boolean gzipFile, BytesProgressWatcher progressWatcher)
throws Exception
{
S3Object s3Object = new S3Object(objectKey);
// Set object explicitly to private access by default.
s3Object.setAcl(AccessControlList.REST_CANNED_PRIVATE);
s3Object.addMetadata(Constants.METADATA_JETS3T_LOCAL_FILE_DATE,
ServiceUtils.formatIso8601Date(new Date(dataFile.lastModified())));
if (dataFile.isDirectory()) {
s3Object.setContentLength(0);
s3Object.setContentType(Mimetypes.MIMETYPE_BINARY_OCTET_STREAM);
} else {
s3Object.setContentType(Mimetypes.getInstance().getMimetype(dataFile));
File uploadFile = transformUploadFile(dataFile, s3Object, encryptionUtil,
gzipFile, progressWatcher);
s3Object.setContentLength(uploadFile.length());
s3Object.setDataInputFile(uploadFile);
// Compute the upload file's MD5 hash.
InputStream inputStream = new BufferedInputStream(new FileInputStream(uploadFile));
if (progressWatcher != null) {
inputStream = new ProgressMonitoredInputStream(inputStream, progressWatcher);
}
s3Object.setMd5Hash(ServiceUtils.computeMD5Hash(inputStream));
if (!uploadFile.equals(dataFile)) {
// Compute the MD5 hash of the *original* file, if upload file has been altered
// through encryption or gzipping.
inputStream = new BufferedInputStream(new FileInputStream(dataFile));
if (progressWatcher != null) {
inputStream = new ProgressMonitoredInputStream(inputStream, progressWatcher);
}
s3Object.addMetadata(
S3Object.METADATA_HEADER_ORIGINAL_HASH_MD5,
ServiceUtils.toBase64(ServiceUtils.computeMD5Hash(inputStream)));
}
}
return s3Object;
}