有人可以建议如何为精细上传者返回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 dev工具):
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.