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

问题描述

我正在使用亚马逊AWS SDK的PHP版本。我有一堆带有 Expires 标题的文件;我想删除该标头并添加 Cache-control 标头。 功能可让我添加标题但不会删除他们。

I am using the PHP version of Amazon's AWS SDK. I have a bunch of files with an Expires header; I want to delete that header and add a Cache-control header instead. The update_object function lets me add headers but not remove them.

建议你可以在复制时更新文件的元数据,但是我已经尝试了它并且它不起作用。以下是我使用的内容:

The answers on this question suggest you can update a file's metadata when you copy it, but I have tried it and it doesn't work. Here is what I used:

$response = $s3->copy_object(
    array(
        'bucket' => $bucket,
        'filename' => $file,
    ),
    array(
        'bucket' => $bucket,
        'filename' => $file2,
    ),
    array(
        'acl' => AmazonS3::ACL_PUBLIC,
        'headers' => array(
            'Content-Type' => 'image/jpeg',
            'Cache-Control' => 'public,max-age=30240000',
        ),
        'meta' => array(
            'x-fake-header' => 'something awesome is happening',
        ),
    )
);

但是,复制的对象与原始对象具有完全相同的标题(仅限Expires和Content-Type) )。我已经尝试了上述各种组合(有和没有Content-Type,Cache-control,meta等)并得到相同的结果。

However, the copied object has the exact same headers as the original object (Expires and Content-Type only). I've tried all manner of combinations of the above (with and without Content-Type, Cache-control, meta, etc) and get the same result.

怎么做我重置了元数据?

How do I reset the metadata?

推荐答案

我刚刚发现复制到对象实际上确实正确更改标题。我正在将其复制到第二个文件以进行测试,以避免覆盖原始文件。

I've just found that copying to object to itself actually does change the headers properly. I was copying it to a second file for testing purposes to avoid overwriting the original.

但由于某些奇怪的原因,复制到不同的文件不会更改标题,但是复制到同一个文件。

But for some strange reason copying to a different file doesn't change the headers, but copying to the same file does.

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

09-03 18:15