gpt4 book ai didi

python - 如何使用Python构建共享访问签名URL?

转载 作者:太空宇宙 更新时间:2023-11-03 17:28:59 25 4
gpt4 key购买 nike

有人可以建议如何为罚款上传者返回 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.

目前我的fine-uploader实例设置如下:

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.

最佳答案

听起来您的存储容器配置不正确。您需要确保它在响应中包含适当的 CORS header 。 the fine uploader azure docs 对此进行了详细介绍。 .

关于python - 如何使用Python构建共享访问签名URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32172253/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com