【问题标题】:how to include the header access token to the Dropzone config如何将标头访问令牌包含到 Dropzone 配置中
【发布时间】:2017-10-10 01:49:51
【问题描述】:

我必须添加标头访问令牌

  $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 } }

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

【问题讨论】:

  • 你能尝试一下标题吗:{ 'Authorization': 'Bearer' + $scope.access_token }

标签: javascript angularjs access-token dropzone.js


【解决方案1】:
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  }
  }

【讨论】:

    【解决方案2】:

    您可以在dropzone 对象的headers options 中添加标题。 检查以下示例中选项中的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},          
        });
    

    【讨论】:

      猜你喜欢
      • 2015-07-20
      • 1970-01-01
      • 1970-01-01
      • 2016-11-23
      • 2017-01-18
      • 2017-09-13
      • 2020-12-25
      • 2022-11-30
      • 1970-01-01
      相关资源
      最近更新 更多