简体   繁体   English

签名/过期/访问密钥ID出现在URL参数中。 的Django /宝途/ S3

[英]Signature/Expires/Access Key ID appearing in URL Params. Django/Boto/S3

Thumbnail URLS have params in them. 缩略图URLS中包含参数。 I'm not sure why. 我不知道为什么。 I think they related to sorl-thumbnail or boto storage we're using. 我认为它们与我们正在使用的sorl-thumbnail或boto存储有关。 How do I remove the additional params from the URL? 如何从URL中删除其他参数? Are they coming from boto/s3 or sorl. 他们是来自boto / s3还是sorl。 I've no idea how to debug. 我不知道如何调试。

使用:AWS_QUERYSTRING_AUTH = False

The extra parameters that are being added are there to implement Query String Authentication . 正在添加的额外参数用于实现查询字符串身份验证 This allows you to pre-sign the URL to private resources stored in S3. 这允许您将URL预先签名为存储在S3中的私有资源。 As long as someone has the pre-signed URL (and it hasn't expired) they will be able to access these resources even though they are not publicly readable. 只要有人拥有预先签名的URL(并且它尚未过期),即使它们不是公开可读的,他们也能够访问这些资源。

Without the extra parameters, there is no way to provide public access to these private S3 resources. 如果没有额外的参数,则无法提供对这些私有S3资源的公共访问。

Works for me: AWS_QUERYSTRING_AUTH = False 适合我:AWS_QUERYSTRING_AUTH = False

using this https://github.com/mstarinteractive/django-s3storage 使用此https://github.com/mstarinteractive/django-s3storage

from myapp.s3storage import S3BotoStorage
from django.contrib.staticfiles.storage import CachedFilesMixin


class CachedStaticS3BotoStorage(CachedFilesMixin, S3BotoStorage):

    """Extends S3BotoStorage to save static files with hashed filenames."""
    pass
StaticRootS3BotoStorage = lambda: CachedStaticS3BotoStorage(location='static')

It's weird behaviour: Google Docs previewer will work and display a preview without the parameters, but will say no preview available if boto appends the signature. 这是一种奇怪的行为:Google Docs预览器将在没有参数的情况下工作并显示预览,但如果boto附加签名,则会说无法预览。

<iframe src="{% trans "https://docs.google.com/viewer?embedded=true&amp;url=" %}{{ document.file.url }}" width="451" height="390" style="border: none;"></iframe>

I must be missing something. 我肯定错过了什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM