【问题标题】:How to append token in Angular Dropzone.js如何在 Angular Dropzone.js 中附加令牌
【发布时间】:2017-09-19 20:56:03
【问题描述】:

我使用 ngx-dropzone-wrapper 为通过令牌认证登录后的 pdf 上传创建 dropzone- dropzone 配置存在于 app.module.ts 中,如下所示-

 const DROPZONE_CONFIG: DropzoneConfigInterface = {
  method: "get",
  url: 'http://9666427d.ngrok.io/api/fileentry/add?token=',
  maxFilesize: 2,
  maxFiles: 1,
  acceptedFiles: '.pdf'
};

我希望用这个 url 附加令牌,我有一个具有以下功能的服务来获取令牌-

  getToken() {
return this.LoginResponse.token;
}

Dropzone 在组件 HTML 中如下所示-

  <dropzone [message]="'Click or drag Synopsis PDF here to upload - Max Allowed Size (2MB) '" id="dropzone"></dropzone>

我不知道如何在 app 模块中给出的 url 中附加令牌。请帮忙!

【问题讨论】:

    标签: angular dropzone.js


    【解决方案1】:

    首先导入以下包类。

    import { DROPZONE_CONFIG } from 'ngx-dropzone-wrapper';
    import { DropzoneConfigInterface } from 'ngx-dropzone-wrapper';
    

    在使用 ngx-dropzone-wrapper 包的组件类中创建一个变量。

    config: DropzoneConfigInterface = { };
    

    然后在构造函数中附加你的令牌:

    constructor(private api: ApiService) {
      this._fetchFiles();
      this.config = {
          url: this.api._getUploadFilesEndPoint()+"?token="+this.api._getToken(),
          method: 'post',
          maxFilesize: 1,
          clickable: true,
          acceptedFiles: '.pdf,'       
        };
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-13
      • 2019-04-13
      • 2021-08-28
      • 2017-11-21
      • 1970-01-01
      • 2019-03-27
      • 2018-04-09
      相关资源
      最近更新 更多