How to get 304 images stored on amazon s3 when using django storages in django app?

I just started storing user uploaded images on Amazon S3. This is pretty good because he took care of my storage problem. However, I struggle when it comes to the fact that the browser caches images.

I am using django repositories. In their docs, they indicate that you can put things in the request header for an image by setting the AWS_HEADER var parameter in your settings. I do this and get no results.

Basically, when an application requests image (s), I get 200 EVERY TIME. ARG ... when I take the browser directly to the image (copy and paste the link into a new window), I get 200, then 304 every time after that.

This is very frustrating because it reloads the image every time. Some pages have up to 25 small thumbnails, and each time the page is reloaded, it reloads.

I maintain my static files using djangos staticfiles and they work properly. I get 200, then 304 after caching the file.

here are my AWS settings in settings.py

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_ACCESS_KEY_ID = '***'
AWS_SECRET_ACCESS_KEY = '***'
AWS_STORAGE_BUCKET_NAME = 'foobar_uploads'
AWS_HEADERS = {
    'Expires': 'Thu, 15 Apr 2020 20:00:00 GMT',
    'Cache-Control': 'max-age=86400',
}

AWS_CALLING_FORMAT = CallingFormat.SUBDOMAIN

here are the request and response headers when the application requests an image: (I replaced what, in my opinion, could be confidential information with * )

##request##
GET /user_uploads/*****/2012/3/17/14/46/thumb_a_28_DSC_0472.jpg?Signature=FVR6T%2BXFwHMmdQ9K3n7Ppp7QxoY%3D&Expires=1332023525&AWSAccessKeyId=***** HTTP/1.1
Host: *****_user_uploads_sandbox.s3.amazonaws.com
Connection: keep-alive
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79 Safari/535.11
Accept: */*
Referer: http://localhost:8000/m/my-photos/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3


##response##
HTTP/1.1 200 OK
x-amz-id-2: Hn3S+3gmeLHIjKCpz+2ocE6aPsLCVHh56jJYTsPHwxU98y89x+9X1Ml202evBUHT
x-amz-request-id: 528CEB880CA89AD3
Date: Sat, 17 Mar 2012 21:32:06 GMT
Cache-Control: max-age=86400
Expires: Thu, 15 Apr 2020 20:00:00 GMT
Last-Modified: Sat, 17 Mar 2012 20:46:29 GMT
ETag: "a3bc70e0c3fc0deb974edf95668e9030"
Accept-Ranges: bytes
Content-Type: image/jpeg
Content-Length: 8608
Server: AmazonS3

Here are the request / response headers when I manually request an image by copying and pasting an image link:

##request##
GET /user_uploads/*****/2012/3/17/14/46/thumb_a_28_DSC_0472.jpg?Signature=FVR6T%2BXFwHMmdQ9K3n7Ppp7QxoY%3D&Expires=1332023525&AWSAccessKeyId=***** HTTP/1.1
Host: porlio_user_uploads_sandbox.s3.amazonaws.com
Connection: keep-alive
Cache-Control: max-age=0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79 Safari/535.11
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
If-None-Match: "a3bc70e0c3fc0deb974edf95668e9030"
If-Modified-Since: Sat, 17 Mar 2012 20:46:29 GMT



##response##
HTTP/1.1 304 Not Modified
x-amz-id-2: FZH0imrbNxziMznhl5zAoo38CaM7Z+TFnd8R6HtTYB3eTmVpCih+1IniKaliRo18
x-amz-request-id: 3CACF77FBB39D088
Date: Sat, 17 Mar 2012 21:33:22 GMT
Last-Modified: Sat, 17 Mar 2012 20:46:29 GMT
ETag: "a3bc70e0c3fc0deb974edf95668e9030"
Server: AmazonS3

, , "If-None-Match:" "If-Modified-Since:". , , , .

?

!

1: . http://coder.cl/2012/01/django-and-amazon-s3/comment-page-1/

+5
2

, django- auth , settings.py:

AWS_QUERYSTRING_AUTH = False

S3 Boto, , django-. , , settings.py ( 34).

, Github django-compressor .

+5

, "If-None-Match" "If-Modified-Since", S3 304, . , , 304.

, Last-Modified / ETag .

, max-age Expires. , . Expires, max-age , ( ).

REDbot .

+1

All Articles