如何更新现有 Amazon S3 文件的元数据? [英] How do I update metadata for an existing Amazon S3 file?

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

问题描述

我需要更新所有 AmazonS3 云文件中的缓存控制标头.但是,我不知道如何使用 jclouds API 做到这一点.我正在使用 apache jclouds 插件.我得到了两个相关的答案:

I need to update the cache control header in all AmazonS3's Cloud Files. However, I can't figure out how I do that using the jclouds API. I'm using apache jclouds plugin. And I got two related answers:

第一个答案是建议使用 SwiftKey Api 类,该类在 grails 的 jcloud 插件中不可用.第二个答案是使用 AWS java sdk,它已经有一个 grails 包装插件 https://grails.org/plugin/aws-sdk 但它不支持元数据更新.

The first answer is suggesting to use SwiftKey Api class which is not available in grails's jcloud plugin. The second answer is using AWS java sdk for which there is already a grails wrapping plugin https://grails.org/plugin/aws-sdk but it doesn't support metadata update.

推荐答案

可以通过执行对象复制来更改元数据(请参阅 如何使用 Amazon S3 SDK 更新元数据):

It is possible to change the metadata by performing an object copy (see How to update metadata using Amazon S3 SDK):

ObjectMetadata metadataCopy = new ObjectMetadata();
// copy previous metadata
metadataCopy.addUserMetadata("newmetadata", "newmetadatavalue");

CopyObjectRequest request = new CopyObjectRequest(bucketName, existingKey, bucketName, existingKey)
      .withNewObjectMetadata(metadataCopy);

amazonS3Client.copyObject(request);

这是否是哲学上的更新"由您决定.

Whether this is philosophically an "update" is up to you to decide.

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

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