Add cache-control header for object in S3?

1,869 views
Skip to first unread message

Matt Billenstein

unread,
Sep 15, 2010, 6:06:58 AM9/15/10
to boto-...@googlegroups.com
Other than uploading the object fresh to S3, is there a way to set a
cache-control header?

Right now I'm doing something like:

key.set_contents_from_filename(path, policy='public-read', headers={'Cache-Control': 'max-age=14400'})

When I upload a new file...

m

--
Matt Billenstein
ma...@vazor.com
http://www.vazor.com/

Chris Moyer

unread,
Sep 15, 2010, 12:31:28 PM9/15/10
to boto-...@googlegroups.com
Does this not work or are you asking for something more like:

key.set_contents_from_filename(path, policy='public-read',
cache_control='4400')

> --
> You received this message because you are subscribed to the Google Groups "boto-users" group.
> To post to this group, send email to boto-...@googlegroups.com.
> To unsubscribe from this group, send email to boto-users+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/boto-users?hl=en.
>
>

--
Chris Moyer

Matt Billenstein

unread,
Sep 15, 2010, 1:22:33 PM9/15/10
to boto-...@googlegroups.com
On Wed, Sep 15, 2010 at 12:31:28PM -0400, Chris Moyer wrote:
> Does this not work or are you asking for something more like:

My example works and I think the interface is fine, but I was wondering
if there was a way to set a header on a file that's already in s3
without uploading it again.

m

Chris Moyer

unread,
Sep 15, 2010, 1:25:03 PM9/15/10
to boto-...@googlegroups.com
Ahh, yeah, that's been a long discussion on here before too. You can
do it, but it's essentially done by copying the file over itself. See
http://groups.google.com/group/boto-users/browse_thread/thread/2d830d1afba2ea05/2275433ff1ff26a0?lnk=gst&q=metadata#2275433ff1ff26a0

Mitchell Garnaat

unread,
Sep 15, 2010, 1:26:19 PM9/15/10
to boto-...@googlegroups.com
But at least using the COPY operation doesn't require you to re-upload the file.

Mitch

Matt Billenstein

unread,
Sep 15, 2010, 3:34:15 PM9/15/10
to boto-...@googlegroups.com
On Wed, Sep 15, 2010 at 01:25:03PM -0400, Chris Moyer wrote:
> Ahh, yeah, that's been a long discussion on here before too. You can
> do it, but it's essentially done by copying the file over itself. See
> http://groups.google.com/group/boto-users/browse_thread/thread/2d830d1afba2ea05/2275433ff1ff26a0?lnk=gst&q=metadata#2275433ff1ff26a0

To follow up -- I think this works properly:

>>> k2.copy(bucket.name, k2.key, metadata={'Content-Type' : 'image/jpeg', 'Cache-Control' : 'max-age=3601'})
<Key: static.flingo.tv,02/02100c0c-4e8d-11df-8480-123139023132/me.jpg>
>>> k3 = _
>>> k3.set_acl('public-read')

The ACL doesn't seem to be preserved across the copy, so it needs to be
reset...

Mitchell Garnaat

unread,
Sep 15, 2010, 3:40:36 PM9/15/10
to boto-...@googlegroups.com
There is a "preserve_acl" boolean param to the copy method that will handle this for you.  It basically does the same think you are doing already but saves you a bit of work.

Mitch

Chris Moyer

unread,
Sep 15, 2010, 3:44:33 PM9/15/10
to boto-...@googlegroups.com
Is it worth creating a convenience method to "update metadata" since
this seems to be a frequent occurrence?

--
Chris Moyer

Matt Billenstein

unread,
Sep 15, 2010, 4:11:49 PM9/15/10
to boto-...@googlegroups.com
On Wed, Sep 15, 2010 at 03:40:36PM -0400, Mitchell Garnaat wrote:
> There is a "preserve_acl" boolean param to the copy method that will
> handle this for you. *It basically does the same think you are doing

> already but saves you a bit of work.

Ah, cool, thanks -- I was looking at the 1.9 docs online and overlooked
this...

Reply all
Reply to author
Forward
0 new messages