如何将标头访问令牌包含到 Dropzone 配置中

Omk*_*xit 4 javascript access-token angularjs dropzone.js

我必须添加标头访问令牌

  $scope.dropzoneConfig = {
            'options': { // passed into the Dropzone constructor
                'url': 'SOME API URL' + $scope.SOME_ID
            },
            'eventHandlers': {
                'sending': function (file, xhr, formData) {
                },
                'success': function (file, response) {
                }
            }};
Run Code Online (Sandbox Code Playgroud)

我的标头访问令牌是

{ headers: { 'Authorization': 'Bearer ' + $scope.access_token } }
Run Code Online (Sandbox Code Playgroud)

我需要将此添加到我试图调用的 url 或 api

Ale*_*huk 6

您可以在添加页眉headers options您的dropzone对象。检查headers以下示例中选项中的属性:

    $("#dropzone").dropzone({
        autoProcessQueue: false,
        url: "/content", 
        maxFiles: 1, 
        clickable: true, 
        acceptedFiles: ".png,.jpg,.jpeg", 
        addRemoveLinks: true, 
        maxFilesize: 10, //MB
        headers:{"Authorization":'Bearer ' + $scope.access_token},          
    });
Run Code Online (Sandbox Code Playgroud)