dsf55s1233 2011-10-04 04:25
浏览 126
已采纳

Amazon S3不缓存图像

I'm using the Amazon S3 PHP Class to upload images, but the cache headers aren't being set. Here's the call I'm using.

$s3->putObjectFile(
    $image_location,
    "bucketname",
    $image_file_name,
    S3::ACL_PUBLIC_READ,
    array(
        "Cache-Control" => "max-age=315360000",
        "Expires" => gmdate("D, d M Y H:i:s T", strtotime("+5 years"))
    )
);

The header response I'm getting for the uploaded image is:

Date: Tue, 04 Oct 2011 04:21:09 GMT
x-amz-request-id: B6BAAAAD9B460160
Content-Length: 34319
x-amz-id-2: Oxxx1hIG2nNKfff3vgH/xx/dffF59O/7a1UWrKrgZlju2g/8WvTcBpccYToULbm
Last-Modified: Tue, 04 Oct 2011 04:19:20 GMT
Server: AmazonS3
ETag: "4846afffbc1a7284fff4a590d5acd6cd"
Content-Type: image/jpeg
Accept-Ranges: bytes
  • 写回答

3条回答 默认 最新

  • douchun1961 2011-10-04 09:35
    关注

    I am not familiar with the Amazon S3 PHP Class but a quick look at the documentation reveals that the putObjectFile method is depreciated and you should use putObject instead.

    <?php
    
        // PUT with custom headers:
        $put = S3::putObject(
            S3::inputFile($file),
            $bucket,
            $uri,
            S3::ACL_PUBLIC_READ,
            array(),
            array( // Custom $requestHeaders
                "Cache-Control" => "max-age=315360000",
                "Expires" => gmdate("D, d M Y H:i:s T", strtotime("+5 years"))
            )
        );
        var_dump($put);
    
    ?>
    

    But why not consider using the official Amazon SDk for PHP?

    You would use create_object to upload a file. The official docs have some good examples:

    // Instantiate the class
    $s3 = new AmazonS3();
    
    $response = $s3->create_object('my-bucket', 'üpløåd/î\'vé nøw béén üpløådéd.txt', array(
        'fileUpload' => 'upload_me.txt',
        'acl' => AmazonS3::ACL_PUBLIC,
        'contentType' => 'text/plain',
        'storage' => AmazonS3::STORAGE_REDUCED,
        'headers' => array( // raw headers
            'Cache-Control' => 'max-age',
            'Content-Encoding' => 'gzip',
            'Content-Language' => 'en-US',
            'Expires' => 'Thu, 01 Dec 1994 16:00:00 GMT',
        ),
        'meta' => array(
            'word' => 'to your mother', // x-amz-meta-word
            'ice-ice-baby' => 'too cold, too cold' // x-amz-meta-ice-ice-baby
        ),
    ));
    
    // Success?
    var_dump($response->isOK());
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元