Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9155123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:32:19+00:00 2026-06-17T12:32:19+00:00

I recently started using Amazon S3 to serve images to my visitors since this

  • 0

I recently started using Amazon S3 to serve images to my visitors since this will reduce the server load. Now, there is a new problem: Today I looked into my AWS billings. I noticed that I have a huge bill waiting for me – there has been a total of 4TB AWS Data Transfer in 20 days.

Obviously this is because the high amount of outgoing Amazon S3 traffic (to Cloudflare which then serves it to the visitors). Now I should to reduce the amount of requested files by setting a Cache header (since Cloudflare’s Crawler will respect that). I have modified my code like this:

$s3->putObjectFile($path, $bucket , 'images/'.$id.'.jpg', S3::ACL_PUBLIC_READ);

to

$s3->putObjectFile($path, $bucket , 'images/'.$id.'.jpg', S3::ACL_PUBLIC_READ, array('Cache-Control' => 'public,max-age=31536000'));

Still, it does not work. Cloudflare does not respect the Cache because the Cache-Control does not show up as "Cache-Control" in the Header but instead as "x-amz-meta-cachecontrol". Cloudflare ignores this.

Does anyone have an easy solution for this?

TL;DR: I have more or less the same problem as this guy: http://support.bucketexplorer.com/topic734.html (that was in 2008)

EDIT: I have stumbled upon this: Amazon S3 not caching images but unfortunately that solution does not work for me.

EDIT 2: Turns out it didn’t work because I was using an old version of the "Amazon S3 class". I updated and the code works now.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:32:20+00:00Added an answer on June 17, 2026 at 12:32 pm

    If you are getting “x-amz-meta-cachecontrol”, it is likely you are not setting the headers correctly. It might just be the exact way you are doing it in your code. This is supposed to work. I am deducing this is php using Amazon S3 PHP Class?

    Try this:

    $s3->putObject(file_get_contents($path), $bucket, $url, S3::ACL_PUBLIC_READ, array(), array('Cache-Control' => 'max-age=31536000, public'));
    

    In the S3 PHP docs putObjectFile is listed under Legacy Methods:

    putObjectFile (string $file, 
                   string $bucket, 
                   string $uri, 
                   [constant $acl = S3::ACL_PRIVATE], 
                   [array $metaHeaders = array()], 
                   [string $contentType = null])
    

    Compare to this:

    putObject (mixed $input, 
               string $bucket, 
               string $uri, 
               [constant $acl = S3::ACL_PRIVATE], 
               [array $metaHeaders = array()], 
               [array $requestHeaders = array()])
    

    You need to set cache-control as a request header, but appears that there is no way to set request headers with putObjectFile, only meta headers. You have to use putObject and give it an empty array for meta headers and then another array with the request headers (including cache-control).

    You can also try some of the other working examples I have listed below.

    See also:

    How to set the Expires and Cache-Control headers for all objects in an AWS S3 bucket with a PHP script (php)

    Updating caching headers for Amazon S3 and CloudFront (python)

    Set cache-control for entire S3 bucket automatically (using bucket policies?)

    http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectGET.html?r=5225

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently started development using Amazon web services. I built a sample application
I recently started using C# and WPF for one of my projects. Is there
I just recently started using Hudson as a CI server for a project of
I recently started using C++/Cli for wrapping purposes. Now I'm at a point where
I recently started using JMeter to load test my webapp, locally on my pc.
I recently started using a new server for a client and am having problems
I have recently started using boost::exception. Now I would like to use boost::errinfo_nested_exception to
I recently started using Lazy throughout my application, and I was wondering if there
I have recently started using Ruby, so quite new to this. My current objective
I recently started using R language and now i am using R for most

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.