Django的Heroku的媒体文件404错误与亚马逊S3

问题描述:

所以,我跟了这问题How要建立一个Django项目Django的存储器和亚马逊S3,但对静态文件和媒体文件不同的文件夹?为了得到我的Django应用程序上传媒体文件到我的Amazon S3的桶中。我使用的Django奥斯卡的方式。 一切似乎正常工作之后我上载的图像,但是当我重新加载页面,图像消失,我得到一个404错误。 我的静态文件做工精细..我没有发现任何问题。

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.

更新:

我已经改变了我的水桶政策,公众和我仍然不能得到图像加载在我的缩略图或者这样:

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/*"
      ]
    }
  ]
}

任何想法?如果我点击链接,我可以看到图像,但是从缩略图它不会加载,并给了我404

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

当我尝试接取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>

更新: 我问家伙在Heroku,这是他们给我的答案是:

UPDATE: I asked the guys on heroku and this was the answer they gave me :

周围有一看,它看起来像Django是网址   发电是不正确的。我生成一个新的URL为您的图像之一   手动测试。新的图像设在这里:   http://s3.amazonaws.com/comprasonline-brazil/media/cache/bc/f5/bcf55748e916eb1979eab9e2713fa97f.jpg?AWSAccessKeyId=AKIAJVPBLRLYHX6EQKUA&Expires=1379587008&Signature=QiU8OvknWHoK7R9YsM%2FG8V%2F4v8s%3D   请注意,该格式是一个有点不同,它具有'/媒体/中   在/缓存前/ B5 / F5等,我就能够查看图像,如   每这张截图。您可能需要重新生成一个新的URL这一个   可能已经被你得到这个经历的时间。看起来像   Django是不是产生这些上传资产的正确网址。该   我用来生成新的URL页面就设在这里。你是   意识到这可能是影响该任何设置?这是有点   超出了我们的范围,我无法找到任何Django的奥斯卡设置   其中设置/缓存/目录下。欢呼声中,里斯

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

我这一个Django奥斯卡的问题?如果是任何人知道我该如何解决这个问题?

I this a django-oscar issue? if yes anyone knows how can i fix this?

看来,你的文件是私人的,正在生成一个签名来访问它们。载至S3由默认文件被设置为私有。你必须明确地设置您的文件公开。

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是不是,你最好使用CloudFront的与您的S3存储作为原点,从直接提供文件的最大选择。

S3 is not the greatest option to serve files from directly, you are best using cloudfront with your s3 bucket as the origin.