简体   繁体   中英

How to Construct the Shared Access Signature URL using Python?

Can someone please advise on how to return a SAS signature for fine-uploader so that I do not get the following error:

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.

currently my fine-uploader instance is set up as following:

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']
        }

    });

The server side that is handling the requests is doing the following:

@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'

Currently I am getting the following error (from chrome dev tools):

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.

Sounds like your storage container isn't properly configured. You'll need to ensure it includes appropriate CORS headers in responses. This is covered in detail in the fine uploader azure docs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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