使用Amazon S3链接到Django中的上载文件

时间:2021-11-01 02:17:37

I am using django-storages backend and I have previously not used Amazon S3. I have migrated to Amazon S3 by uploading the files via Firefox's S3 Manager.

我正在使用django-storages后端,我之前没有使用过Amazon S3。我已经通过Firefox的S3 Manager上传文件迁移到了Amazon S3。

THe problem is, with this code:

问题是,使用此代码:

<a href="{{ MEDIA_URL }}{{ g.photo }}" class="lightbox" title="{{ g.description }}">
    {%  thumbnail g.photo '95x95' crop="center" as im %}
        <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}" />
    {% endthumbnail %}
</a>

The request generated does not include the required params in the GET request, like the Signature. However, the sorl-generated thumbnails work!

生成的请求不包括GET请求中所需的参数,如签名。但是,sorl生成的缩略图有效!

Is there something I'm missing with regards to uploading my files in S3? Is there additional code to be added in the href? Why is sorl able to retrieve the files and create a thumbnail out of it?

关于在S3上传文件,我有什么遗漏吗?是否需要在href中添加其他代码?为什么sorl能够检索文件并从中创建缩略图?

1 个解决方案

#1


1  

The file is not accessible publicly. This may have happened on uploading or due bucket restrictions.

该文件无法公开访问。这可能发生在上传或存储桶限制上。

You could either change the ACL settings in S3 Manager for this file to public access (if only this file should be publicly readable), or create a Bucket policy for fine-grained permissions on the bucket - you can do that in the AWS Console.

您可以将S3 Manager中的ACL设置更改为公共访问权限(如果此文件只能公开访问),或者为存储桶上的细粒度权限创建Bucket策略 - 您可以在AWS控制台中执行此操作。

If any file in the bucket shall be public, you should change the default ACL setting in your S3 client accordingly.

如果存储桶中的任何文件是公共的,则应相应地更改S3客户端中的默认ACL设置。

#1


1  

The file is not accessible publicly. This may have happened on uploading or due bucket restrictions.

该文件无法公开访问。这可能发生在上传或存储桶限制上。

You could either change the ACL settings in S3 Manager for this file to public access (if only this file should be publicly readable), or create a Bucket policy for fine-grained permissions on the bucket - you can do that in the AWS Console.

您可以将S3 Manager中的ACL设置更改为公共访问权限(如果此文件只能公开访问),或者为存储桶上的细粒度权限创建Bucket策略 - 您可以在AWS控制台中执行此操作。

If any file in the bucket shall be public, you should change the default ACL setting in your S3 client accordingly.

如果存储桶中的任何文件是公共的,则应相应地更改S3客户端中的默认ACL设置。