本文整理汇总了Java中com.amazonaws.services.s3.AmazonS3.putObject方法的典型用法代码示例。如果您正苦于以下问题:Java AmazonS3.putObject方法的具体用法?Java AmazonS3.putObject怎么用?Java AmazonS3.putObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.s3.AmazonS3
的用法示例。
在下文中一共展示了AmazonS3.putObject方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: webHookDump
import com.amazonaws.services.s3.AmazonS3; //导入方法依赖的package包/类
public static String webHookDump(InputStream stream, String school, String extension) {
if (stream != null) {
extension = extension == null || extension.isEmpty() ? ".xml" : extension.contains(".") ? extension : "." + extension;
String fileName = "webhooks/" + school + "/" + school + "_" + Clock.getCurrentDateDashes() + "_" + Clock.getCurrentTime() + extension;
AmazonS3 s3 = new AmazonS3Client();
Region region = Region.getRegion(Regions.US_WEST_2);
s3.setRegion(region);
try {
File file = CustomUtilities.inputStreamToFile(stream);
s3.putObject(new PutObjectRequest(name, fileName, file));
return CustomUtilities.fileToString(file);
} catch (Exception e) {
e.printStackTrace();
}
}
return "";
}
示例2: put
import com.amazonaws.services.s3.AmazonS3; //导入方法依赖的package包/类
public void put(Object[] params) {
String key = params[0].toString();
File file = new File(params[0].toString());
AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
try {
s3client.putObject(new PutObjectRequest(bucketName, key, file));
} catch (AmazonServiceException ase) {
System.out.println("Caught an AmazonServiceException, which " +
"means your request made it " +
"to Amazon S3, but was rejected with an error response" +
" for some reason.");
System.out.println("Error Message:" + ase.getMessage());
System.out.println("HTTP Status Code:" + ase.getStatusCode());
System.out.println("AWS Error Code:" + ase.getErrorCode());
System.out.println("Error Type:" + ase.getErrorType());
System.out.println("Request ID:" + ase.getRequestId());
} catch (AmazonClientException ace) {
System.out.println("Caught an AmazonClientException, which " +
"means the client encountered " +
"an internal error while trying to " +
"communicate with S3, " +
"such as not being able to access the network.");
System.out.println("Error Message: " + ace.getMessage());
}
}
示例3: uploadFile
import com.amazonaws.services.s3.AmazonS3; //导入方法依赖的package包/类
/**
* Use UploadFile.BucketName
* @param keyName
* @param filePathToUpload
* @param BUCKET_NAME
*/
public static void uploadFile(String keyName,File fileToUpload,String BUCKET_NAME,String contentType) {
AmazonS3 s3Client = s3client();
System.out.println(s3Client);
try {
System.out.println("Uploading a new object to S3 from a file\n");
File file = fileToUpload;
PutObjectRequest objectToPut = new PutObjectRequest(BUCKET_NAME, keyName, file);
ObjectMetadata meta = new ObjectMetadata();
meta.setContentType(contentType);
objectToPut.setMetadata(meta);
s3Client.putObject(objectToPut);
} catch (AmazonServiceException ase) {
System.out.println("Caught an AmazonServiceException, which " +
"means your request made it " +
"to Amazon S3, but was rejected with an error response" +
" for some reason.");
System.out.println("Error Message: " + ase.getMessage());
System.out.println("HTTP Status Code: " + ase.getStatusCode());
System.out.println("AWS Error Code: " + ase.getErrorCode());
System.out.println("Error Type: " + ase.getErrorType());
System.out.println("Request ID: " + ase.getRequestId());
} catch (AmazonClientException ace) {
System.out.println("Caught an AmazonClientException, which " +
"means the client encountered " +
"an internal error while trying to " +
"communicate with S3, " +
"such as not being able to access the network.");
System.out.println("Error Message: " + ace.getMessage());
}
}
示例4: storeObject
import com.amazonaws.services.s3.AmazonS3; //导入方法依赖的package包/类
public static void storeObject(String contentType,
String content,
String destBucket,
String destKey) throws UnsupportedEncodingException {
AmazonS3 s3Client = AmazonS3Provider.getS3Client();
ObjectMetadata metadata = prepareObjectMetadata(contentType, content);
s3Client.putObject(
destBucket,
destKey,
new StringInputStream(content),
metadata);
}
示例5: createSomeObjects
import com.amazonaws.services.s3.AmazonS3; //导入方法依赖的package包/类
protected static void createSomeObjects(AmazonS3 s3) {
String bucketName = "bucket-" + UUID.randomUUID().toString().toLowerCase();
s3.createBucket(bucketName);
for (int i = 0; i < 3; i++) {
s3.putObject(bucketName, "OBJECT-" + UUID.randomUUID(), createString(4096));
}
// Usage data are generated in the async way, hope it will be available after wait.
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
示例6: sendToQueueUsingS3
import com.amazonaws.services.s3.AmazonS3; //导入方法依赖的package包/类
public static String sendToQueueUsingS3(AmazonSQS sqs, String queueUrl, AmazonS3 s3, String bucketName,
Map<String, String> headers, byte[] message, Callable<String> s3IdFactory) {
Preconditions.checkNotNull(sqs);
Preconditions.checkNotNull(s3);
Preconditions.checkNotNull(queueUrl);
Preconditions.checkNotNull(bucketName);
Preconditions.checkNotNull(message);
String s3Id;
try {
s3Id = s3IdFactory.call();
} catch (final Exception e1) {
throw new RuntimeException(e1);
}
final ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(message.length);
for (final Entry<String, String> header : headers.entrySet()) {
metadata.setHeader(header.getKey(), header.getValue());
}
s3.putObject(bucketName, s3Id, new ByteArrayInputStream(message), metadata);
try {
sqs.sendMessage(queueUrl, s3Id);
} catch (final RuntimeException e) {
try {
s3.deleteObject(bucketName, s3Id);
throw e;
} catch (final RuntimeException e2) {
throw new io.reactivex.exceptions.CompositeException(e, e2);
}
}
return s3Id;
}
示例7: run
import com.amazonaws.services.s3.AmazonS3; //导入方法依赖的package包/类
@Override
public void run() {
super.run();
String awsCredentialsProfile = this.readStringArgument("awsProfile", "default");
String bucket = this.readStringArgument("bucket");
String objectKey = this.readStringArgument("objectKey");
String sourceFilePath = this.readStringArgument("sourceFile");
File sourceFile = new File(sourceFilePath);
if (sourceFile.exists()) {
try {
AmazonS3 s3Client = new AmazonS3Client(
new ProfileCredentialsProvider(awsCredentialsProfile));
s3Client.putObject(new PutObjectRequest(bucket, objectKey, sourceFile));
} catch (Exception ex) {
throw new RuntimeException(String.format(
"Failed to upload file \"%s\" to S3 bucket \"%s\"",
sourceFilePath,
bucket), ex);
}
} else {
throw new RuntimeException(String.format(
"Source file \"%s\" doesn't exist",
sourceFilePath));
}
}
示例8: putToS3
import com.amazonaws.services.s3.AmazonS3; //导入方法依赖的package包/类
/**
* Performs an S3 Put Object operation storing the UTF-8 bytes of logMsg under the given key
* using construction provided AWS credentials.
*
* @param objectKey the S3 object key. may not be null or whitespace only.
* @param logMsg the message to store
* @throws IllegalArgumentException if objectKey is whitespace only.
*/
void putToS3(String objectKey, String logMsg)
{
if(objectKey == null)
throw new NullPointerException("objectKey");
if(objectKey.trim().length() == 0)
throw new IllegalArgumentException("objectKey may not be only whitespace.");
/*
* Make the client used to send the log msg to S3.
*/
AmazonS3 client;
{
Regions regions = Regions.US_EAST_1;
if(_credentials == null)
{
client = AmazonS3ClientBuilder.standard() // get creds from environment
.withRegion(regions)
.build();
}
else
{
client = AmazonS3ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(_credentials))
.withRegion(regions)
.build();
}
}
/*
* Store the log msg in S3.
*/
byte[] logMsgBytes = logMsg.getBytes(StandardCharsets.UTF_8);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(logMsgBytes.length);
client.putObject(_bucketName, objectKey, new ByteArrayInputStream(logMsgBytes), metadata);
_logger.debug("exiting");
}