问题
So i have followed this question How to set-up a Django project with django-storages and Amazon S3, but with different folders for static files and media files? in order to get my django app uploading media files to my amazon S3 bucket. I am using django-oscar by the way. Everything seemed to work fine right after i uploaded the image, but when i reload the page, the images disappear and i get a 404 error. My static files work fine.. i have found no problems.
UPDATE:
I have changed my bucket policies to public and i still can't get the images to load on my thumbnails or so :
{
"Version":"2008-10-17",
"Statement":[{
"Sid":"AllowPublicRead",
"Effect":"Allow",
"Principal": {
"AWS": "*"
},
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::bucket/*"
]
}
]
}
Any ideas? if i click on the link i can see the image, but from the thumbnails it doesn't load and gives me the 404
When i try to acess the 404 links i get a
<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
<Key>cache/7b/4d/7b4d647e0faa51cb4226f13b780ba320.jpg</Key>
<RequestId>4BF12C367D0C65D1</RequestId>
<HostId>
b7c4LraxQtVGMe3bE+hAPOSBo9nrHE8DiyLbsBchfmdAul8F0Uw0+pKkO+PM6z/i
</HostId>
</Error>
UPDATE: I asked the guys on heroku and this was the answer they gave me :
Hi, Having a look around, it looks like the URL that Django is generating isn't correct. I generated a new URL for one of your images manually to test it. The new image was located here: http://s3.amazonaws.com/comprasonline-brazil/media/cache/bc/f5/bcf55748e916eb1979eab9e2713fa97f.jpg?AWSAccessKeyId=AKIAJVPBLRLYHX6EQKUA&Expires=1379587008&Signature=QiU8OvknWHoK7R9YsM%2FG8V%2F4v8s%3D Notice that the format is a bit different, and it has '/media/ in front of the /cache/b5/f5 etc. I was then able to view the image, as per this screenshot. You may need to regenerate a new URL as this one will probably have expired by the time you get this. It looks like Django isn't generating the proper URLs for these uploaded assets. The page that I used to generate the new URL is located here. Are you aware of any settings which could be impacting this? It is it a bit beyond our scope, and I wasn't able to find any django-oscar setting which set the '/cache/' directory. Cheers, Rhys
I this a django-oscar issue? if yes anyone knows how can i fix this?
回答1:
It appears that your files are private and a signature is being generated to access them. By default files uploaded to s3 are set to private. You will have to explicitly set your files to public.
S3 is not the greatest option to serve files from directly, you are best using cloudfront with your s3 bucket as the origin.
来源:https://stackoverflow.com/questions/18624609/django-heroku-media-files-404-error-with-amazon-s3