本文整理汇总了Java中com.amazonaws.services.s3.AmazonS3Client.putObject方法的典型用法代码示例。如果您正苦于以下问题:Java AmazonS3Client.putObject方法的具体用法?Java AmazonS3Client.putObject怎么用?Java AmazonS3Client.putObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.s3.AmazonS3Client
的用法示例。
在下文中一共展示了AmazonS3Client.putObject方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: uploadToS3
import com.amazonaws.services.s3.AmazonS3Client; //导入方法依赖的package包/类
public static void uploadToS3() {
// upload to s3 bucket
AWSCredentials awsCredentials = SkillConfig.getAWSCredentials();
AmazonS3Client s3Client = awsCredentials != null ? new AmazonS3Client(awsCredentials) : new AmazonS3Client();
File folder = new File("c:/temp/morse/" + DOT + "/mp3/");
File[] listOfFiles = folder.listFiles();
for (File file : listOfFiles) {
if (file.isFile()) {
if (!s3Client.doesObjectExist("morseskill", DOT + "/" + file.getName())) {
PutObjectRequest s3Put = new PutObjectRequest("morseskill", DOT + "/" + file.getName(), file).withCannedAcl(CannedAccessControlList.PublicRead);
s3Client.putObject(s3Put);
System.out.println("Upload complete: " + file.getName());
}
else {
System.out.println("Skip as " + file.getName() + " already exists.");
}
}
}
}
示例2: setup
import com.amazonaws.services.s3.AmazonS3Client; //导入方法依赖的package包/类
@Before
public void setup() throws UnsupportedEncodingException, IOException {
/*
* Patch the handler to use this test's factory which produces a mock client.
*/
S3MockClientFactory f;
try {
f = new S3MockClientFactory(tmpFolder);
} catch (Exception e) {
throw new RuntimeException("unable to start s3proxy", e);
}
AmazonS3Client client = f.newInstance();
client.createBucket(S3_BUCKET);
this.clientFactory = f;
/*
* Upload config file
*/
String payload = IOUtils.toString(new InputStreamReader(
this.getClass().getResourceAsStream("/config/handler_config.json"), "UTF-8"));
client.putObject(S3_BUCKET, "bender/config.json", payload);
/*
* Export config file as env var
*/
envVars.set("BENDER_CONFIG", "s3://" + S3_BUCKET + "/bender/config.json");
}
示例3: uploadFileToS3
import com.amazonaws.services.s3.AmazonS3Client; //导入方法依赖的package包/类
protected static String uploadFileToS3(BufferedImage image, String word, Boolean codeOnly) throws IOException {
ByteArrayInputStream bis = null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
String bucket = SkillConfig.getS3BucketName();
String fileKey = getFileKey(word, codeOnly);
ImageIO.write(image, "png", bos);
byte[] bImageData = bos.toByteArray();
bis = new ByteArrayInputStream(bImageData);
// upload to s3 bucket
AWSCredentials awsCredentials = SkillConfig.getAWSCredentials();
AmazonS3Client s3Client = awsCredentials != null ? new AmazonS3Client(awsCredentials) : new AmazonS3Client();
PutObjectRequest s3Put = new PutObjectRequest(bucket, fileKey, bis, null).withCannedAcl(CannedAccessControlList.PublicRead);
s3Client.putObject(s3Put);
return getS3Url(word, codeOnly);
} finally {
bos.close();
if (bis != null) bis.close();
}
}
示例4: main
import com.amazonaws.services.s3.AmazonS3Client; //导入方法依赖的package包/类
public static void main (String[] args) throws Exception {
String credentials = new String("secretKey=MD/FGPCuKkq9EBCpV0qXbfTbaQByFdQYPiM9/BzA" +
"\n" + "accessKey=AKIAICG6X3TDB3GIBQIQ");
AmazonS3Client s3 = new AmazonS3Client(new PropertiesCredentials(new ByteArrayInputStream(credentials.getBytes())));
File f = new File("C:\rfcs\rfc4912.txt");
String s = readFileAsString(f);
for (int i = 0; i < 1000; i++) {
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(s.getBytes().length);
s3.putObject("cryptosearch", "test/"+i, new ByteArrayInputStream(s.getBytes()), metadata);
}
}
示例5: putObject
import com.amazonaws.services.s3.AmazonS3Client; //导入方法依赖的package包/类
@Override
public PutObjectResult putObject(PutObjectRequest request) throws Exception
{
RefCountedClient holder = client.get();
AmazonS3Client amazonS3Client = holder.useClient();
try
{
return amazonS3Client.putObject(request);
}
finally
{
holder.release();
}
}
示例6: uploadSchema
import com.amazonaws.services.s3.AmazonS3Client; //导入方法依赖的package包/类
@Override
public void uploadSchema(BackupRestoreContext ctx, String schema) throws Exception {
final String nodeId = ctx.getNodeId();
final AmazonS3Client amazonS3Client = getAmazonS3Client(ctx);
final String key = getPrefixKey(ctx) + "/" + nodeId + "/" + StorageUtil.SCHEMA_FILE;
final InputStream stream = new ByteArrayInputStream(schema.getBytes(StandardCharsets.UTF_8));
amazonS3Client.putObject(getBucketName(ctx), key, stream, new ObjectMetadata());
}
示例7: sendToQueueUsingS3
import com.amazonaws.services.s3.AmazonS3Client; //导入方法依赖的package包/类
public static String sendToQueueUsingS3(AmazonSQSClient sqs, String queueUrl, AmazonS3Client s3,
String bucketName, Map<String, String> headers, byte[] message,
Func0<String> s3IdFactory) {
Preconditions.checkNotNull(sqs);
Preconditions.checkNotNull(s3);
Preconditions.checkNotNull(queueUrl);
Preconditions.checkNotNull(bucketName);
Preconditions.checkNotNull(message);
String s3Id = s3IdFactory.call();
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(message.length);
for (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 (RuntimeException e) {
try {
s3.deleteObject(bucketName, s3Id);
throw e;
} catch (RuntimeException e2) {
throw new CompositeException(e, e2);
}
}
return s3Id;
}