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

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

问题描述

我正在查看 Amazon S3 示例,这些示例用于插入/删除...

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

但我想用新数据更新现有的 blob.基本上内容是一个文本文件,并且文本已经被修改,我想让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?

推荐答案

更新 Amazon S3 中的现有对象不会不同于首先创建它,即使用非常相同的 PUT Object 操作来上传对象并将覆盖现有对象(如果它不受其他方式保护,例如通过 使用存储桶策略对象版本控制)

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)

您可以在使用适用于 Java 的 AWS 开发工具包上传对象中找到完整的代码示例,主要部分归结为:

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
");
    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天全站免登陆