【问题标题】:How to Construct the Shared Access Signature URL using Python?如何使用 Python 构造共享访问签名 URL?
【发布时间】:2015-11-17 06:48:18
【问题描述】:

有人可以告诉我如何为精细上传者返回 SAS 签名,这样我就不会收到以下错误:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:5000' is therefore not allowed access. The response had HTTP status code 400.

目前我的精细上传实例设置如下:

var uploader = new qq.azure.FineUploader({

        debug: true,
        element: document.getElementById("fine-uploader"),
        request: {
            endpoint: 'https://asilverman.blob.core.windows.net/picdepot'
        },
        cors: {
            //all requests are expected to be cross-domain requests
            expected: true,
            sendCredentials: true

        },
        signature: {
            customHeaders: {'Access-Control-Allow-Origin': true},
            endpoint: '/sas'
        },
        uploadSuccess: {
            endpoint: ''
        },
        scaling: {
            sendOriginal: false,

            sizes: [
                {name: "", maxSize: 800}
            ]
        },
        validation: {
            allowedExtensions: ['jpeg', 'jpg', 'png']
        }

    });

处理请求的服务器端正在执行以下操作:

@login_required
@app.route('/sas', methods=['GET'])
def sas():
    container_name = 'https://asilverman.blob.core.windows.net/picdepot'
    sas = SharedAccessSignature(account_name=app.config['AZURE_ACCOUNT'], account_key=app.config['AZURE_KEY'])
    access_policy = AccessPolicy()
    access_policy.start = (datetime.datetime.utcnow() + datetime.timedelta(seconds=-120)).strftime('%Y-%m-%dT%H:%M:%SZ')
    access_policy.expiry = (datetime.datetime.utcnow() + datetime.timedelta(seconds=120)).strftime('%Y-%m-%dT%H:%M:%SZ')
    access_policy.permission = 'w'
    sap = SharedAccessPolicy(access_policy)
    sas_token = sas.generate_signed_query_string(container_name, 'c', sap)
    return request.args['bloburi'] + '?' + sas_token + '&' + 'comp=list&restype=container'

目前我收到以下错误(来自 chrome 开发工具):

XMLHttpRequest cannot load https://asilverman.blob.core.windows.net/picdepot/8622a0a3-efb6-478b-891a-8…Mj1uvtPisX6s=&sr=c&se=2015-08-23T22%3A35%3A47Z&comp=list&restype=container. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:5000' is therefore not allowed access. The response had HTTP status code 400.

【问题讨论】:

    标签: python azure azure-storage azure-blob-storage fine-uploader


    【解决方案1】:

    听起来您的存储容器配置不正确。您需要确保它在响应中包含适当的 CORS 标头。这在the fine uploader azure docs中有详细介绍。

    【讨论】:

    • 您能帮我解释一下如何配置容器以使其包含适当的 CORS 标头吗?
    猜你喜欢
    • 1970-01-01
    • 2020-05-09
    • 1970-01-01
    • 2021-01-03
    • 2021-04-14
    • 2016-04-01
    • 2018-10-23
    • 2014-09-22
    相关资源
    最近更新 更多