我可以更新现有的Amazon S3的对象吗? [英] Can I update an existing Amazon S3 object?

查看:135
本文介绍了我可以更新现有的Amazon S3的对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找Amazon S3的样品,并且样品在那里为插入/删除...

I was looking at Amazon S3 Samples, and the samples are there for inserts/deletes...

但我想更新与新的数据现有的斑点。基本内容是一个文本文件,该文本进行了修改,我希望S3对象来存储新的文本内容。

But I want to update an existing blob with fresh data. Basically the content is a text file, and the text has been modified, I want the S3 object to store the new text content.

我如何做到这一点在Java中?

How do I do this in Java?

推荐答案

更​​新现有对象亚马逊S3 不从第一个地方创建它,即同样的 PUT对象的操作不同的是用于上传的目的和将覆盖现有酮(如果它不是由其他方式,例如通过使用铲斗策略保护对象版本

Updating an existing object in Amazon S3 doesn't differ from creating it in the first place, i.e. the very same PUT Object operation is used to upload the object and will overwrite the existing one (if it isn't protected by other means, e.g. via Using Bucket Policies or Object Versioning)

您可以在上传一张完整的code样本对象使用AWS SDK的Java < /一>,主体部分可以归结为:

You can find a complete code sample in Upload an Object Using the AWS SDK for Java, the main part boils down to:

AmazonS3 s3client = new AmazonS3Client(new PropertiesCredentials(
        S3Sample.class.getResourceAsStream(
                "AwsCredentials.properties")));
try {
    System.out.println("Uploading a new object to S3 from a file\n");
    File file = new File(uploadFileName);
    s3client.putObject(new PutObjectRequest(
                             bucketName, keyName, 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.");
    // ... error handling based on exception details
}

这篇关于我可以更新现有的Amazon S3的对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆