本文整理汇总了Java中com.amazonaws.services.s3.model.PutObjectRequest.setStorageClass方法的典型用法代码示例。如果您正苦于以下问题:Java PutObjectRequest.setStorageClass方法的具体用法?Java PutObjectRequest.setStorageClass怎么用?Java PutObjectRequest.setStorageClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.s3.model.PutObjectRequest
的用法示例。
在下文中一共展示了PutObjectRequest.setStorageClass方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: uploadTextToS3Bucket
import com.amazonaws.services.s3.model.PutObjectRequest; //导入方法依赖的package包/类
public void uploadTextToS3Bucket(String bucketName, String key, String content, String storageClass) throws TranscodeException{
ObjectMetadata objectMetaData = new ObjectMetadata();
byte[] bytes = content.getBytes();
objectMetaData.setContentLength(bytes.length);
objectMetaData.setContentType("text/html; charset=utf-8");
try {
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, inputStream, objectMetaData);
if (storageClass.equalsIgnoreCase(StorageClass.ReducedRedundancy.name())) {
putObjectRequest.setStorageClass(StorageClass.ReducedRedundancy);
}
final long fileSizeInBytes = bytes.length;
putObjectRequest.setGeneralProgressListener(new ProgressListener() {
private long bytesTransferred = 0;
private int currentPercentage = 0;
@Override
public void progressChanged(ProgressEvent progressEvent) {
bytesTransferred += progressEvent.getBytesTransferred();
int percentTransferred = (int) (bytesTransferred * 100 / fileSizeInBytes);
if (percentTransferred%10 == 0 && percentTransferred != currentPercentage) {
logger.info("Transferred {}% of {} bytes.", percentTransferred, fileSizeInBytes);
currentPercentage = percentTransferred;
}
}
});
Upload upload = tm.upload(putObjectRequest);
if (upload!=null) {
upload.waitForCompletion();
} else {
logger.error("Did not get upload detail from S3 for asset with key " + key);
throw new TranscodeException("Did not get upload detail from S3 for asset with key " + key);
}
} catch (AmazonClientException | InterruptedException e) {
throw new TranscodeException(e.getMessage());
}
}
示例2: writeData
import com.amazonaws.services.s3.model.PutObjectRequest; //导入方法依赖的package包/类
private void writeData( AmazonKey amazonKey, String bucket, String key, Map<String, String> metadata, StorageClass storage, String mimetype, cfData data, int retry, int retryseconds, String acl, String aes256key, Map<String, String> customheaders ) throws Exception {
if ( mimetype == null ) {
if ( data.getDataType() == cfData.CFBINARYDATA )
mimetype = "application/unknown";
else if ( cfData.isSimpleValue( data ) )
mimetype = "text/plain";
else
mimetype = "application/json";
// Check to see if the mime type is in the metadata
if ( metadata != null && metadata.containsKey( "Content-Type" ) )
mimetype = metadata.get( "Content-Type" );
}
InputStream ios = null;
long size = 0;
if ( data.getDataType() == cfData.CFSTRINGDATA ) {
ios = new java.io.ByteArrayInputStream( data.getString().getBytes() );
size = data.getString().length();
} else if ( data.getDataType() == cfData.CFBINARYDATA ) {
ios = new java.io.ByteArrayInputStream( ( (cfBinaryData) data ).getByteArray() );
size = ( (cfBinaryData) data ).getLength();
} else {
serializejson json = new serializejson();
StringBuilder out = new StringBuilder();
json.encodeJSON( out, data, false, CaseType.MAINTAIN, DateType.LONG );
size = out.length();
mimetype = "application/json";
ios = new java.io.ByteArrayInputStream( out.toString().getBytes() );
}
// Setup the object data
ObjectMetadata omd = new ObjectMetadata();
if ( metadata != null )
omd.setUserMetadata( metadata );
omd.setContentType( mimetype );
omd.setContentLength( size );
AmazonS3 s3Client = getAmazonS3( amazonKey );
// Let us run around the number of attempts
int attempts = 0;
while ( attempts < retry ) {
try {
PutObjectRequest por = new PutObjectRequest( bucket, key, ios, omd );
por.setStorageClass( storage );
if ( aes256key != null && !aes256key.isEmpty() )
por.setSSECustomerKey( new SSECustomerKey( aes256key ) );
if ( acl != null && !acl.isEmpty() )
por.setCannedAcl( amazonKey.getAmazonCannedAcl( acl ) );
if ( customheaders != null && !customheaders.isEmpty() ) {
Iterator<String> it = customheaders.keySet().iterator();
while ( it.hasNext() ) {
String k = it.next();
por.putCustomRequestHeader( k, customheaders.get( k ) );
}
}
s3Client.putObject( por );
break;
} catch ( Exception e ) {
cfEngine.log( "Failed: AmazonS3Write(bucket=" + bucket + "; key=" + key + "; attempt=" + ( attempts + 1 ) + "; exception=" + e.getMessage() + ")" );
attempts++;
if ( attempts == retry )
throw e;
else
Thread.sleep( retryseconds * 1000 );
}
}
}
示例3: writeFile
import com.amazonaws.services.s3.model.PutObjectRequest; //导入方法依赖的package包/类
private void writeFile( AmazonKey amazonKey, String bucket, String key, Map<String, String> metadata, StorageClass storage, String localpath, int retry, int retryseconds, boolean deletefile, boolean background, String callback, String callbackdata, String appname, String acl, String aes256key, Map<String, String> customheaders ) throws Exception {
File localFile = new File( localpath );
if ( !localFile.isFile() )
throw new Exception( "The file specified does not exist: " + localpath );
// Push this to the background loader to handle and return immediately
if ( background ) {
BackgroundUploader.acceptFile( amazonKey, bucket, key, metadata, storage, localpath, retry, retryseconds, deletefile, callback, callbackdata, appname, acl, aes256key, customheaders );
return;
}
// Setup the object data
ObjectMetadata omd = new ObjectMetadata();
if ( metadata != null )
omd.setUserMetadata( metadata );
AmazonS3 s3Client = getAmazonS3( amazonKey );
// Let us run around the number of attempts
int attempts = 0;
while ( attempts < retry ) {
try {
PutObjectRequest por = new PutObjectRequest( bucket, key, localFile );
por.setMetadata( omd );
por.setStorageClass( storage );
if ( acl != null && !acl.isEmpty() )
por.setCannedAcl( amazonKey.getAmazonCannedAcl( acl ) );
if ( aes256key != null && !aes256key.isEmpty() )
por.setSSECustomerKey( new SSECustomerKey( aes256key ) );
if ( customheaders != null && !customheaders.isEmpty() ) {
Iterator<String> it = customheaders.keySet().iterator();
while ( it.hasNext() ) {
String k = it.next();
por.putCustomRequestHeader( k, customheaders.get( k ) );
}
}
s3Client.putObject( por );
break;
} catch ( Exception e ) {
cfEngine.log( "Failed: AmazonS3Write(bucket=" + bucket + "key=" + key + "; file=" + localFile + "; attempt=" + ( attempts + 1 ) + "; exception=" + e.getMessage() + ")" );
attempts++;
if ( attempts == retry )
throw e;
else
Thread.sleep( retryseconds * 1000 );
}
}
// delete the file now that it is a success
if ( deletefile )
localFile.delete();
}