I am using django-storages' s3boto backend as my default storage backend.
If I upload to my publicly accessible bucket via AWS console, I have no problem accessing it. If I use my Django form to save a file, the file appears in the AWS console with its correct size. But the link to file displays a broken image, both using AWS's open
menu command and in the Django admin.
My relavent settings are:
AWS_ACCESS_KEY_ID = '***'
AWS_SECRET_ACCESS_KEY = '***'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_STORAGE_BUCKET_NAME = 'mybucket'
AWS_QUERYSTRING_AUTH = False
Update:
I checked the image url with curl -v
, the response is HTTP/1.1 200 OK
. The response headers are:
< HTTP/1.1 200 OK
< x-amz-id-2: /kR/hcgWI2vUOP7/1+kqAsKfSSx4BWtxnipNcQAadeRaJzmNuBIgD17Wff9N856T
< x-amz-request-id: 17C13B7A2B20E50A
< Date: Thu, 19 Jul 2012 05:05:58 GMT
< Last-Modified: Wed, 18 Jul 2012 19:26:48 GMT
< ETag: "35b2ef1fb7552b850cf477f04141dddc"
< Accept-Ranges: bytes
< Content-Type: image/jpeg
< Content-Length: 101086
< Server: AmazonS3
Then the binary bytes start flowing. So the file must be corrupted during the upload somehow.
Because I am using <input type="file" multiple>
in the upload form, I handle the file upload manually like this:
if self.request.FILES:
files = self.request.FILES.getlist('files')
for file in files:
try:
# Check the file is an image
Image.open(file).verify()
except:
# not an image
pass
else:
photo = Photo()
photo.image = file
photo.save()
This works fine with the default storage backend, but apparently there is something wrong when using s3boto backend.
What do you think I might be doing wrong?