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

时间:2017-05-11 07:22:01

标签: javascript angularjs access-token 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) {
                }
            }};

我的标头访问令牌是

{ headers: { 'Authorization': 'Bearer ' + $scope.access_token } }

我需要将其添加到我要调用的网址或api

2 个答案:

答案 0 :(得分:1)

您可以在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},          
    });

答案 1 :(得分:0)

const getUploadParams = ({ file, meta }) => {
    const body = new FormData();
    let headers;
    UserTool.getToken((token) => {
      headers= { Authorization: `Bearer ${token}` }     
      body.append('file', file, file.name)      
    });
    return { url: UrlConfig.tileset.uploadUrl, body, headers  }
  }