7

使用https://github.com/valor-software/ng2-file-upload拖放文件附件。它允许文件夹被拖放并附加到 chrome 浏览器中。

我的 HTML 模板:

 <div ng2FileDrop
   [ngClass]="{'nv-file-over': hasBaseDropZoneOver}"
   (fileOver)="fileOverBase($event)"
   [uploader]="uploader"
   class="well my-drop-zone">
 <div class="attachment-scroller">
  <div class="row">
    <div class="col-md-9">
      <table class="table upload-attachment">
        <tbody>
        <tr>
          <input type="file" ng2FileSelect [uploader]="uploader"  id="files" multiple  />
          <label for="files">+ Choose files to upload or drop them here</label>
        </tr>
        </tbody>
      </table>
    </div>
  </div>

  <div class="attachment-row" *ngIf="uploader.queue.length > 0">
    <div class="col-md-9">
      <div *ngFor="let item of uploader.queue">
        <div class="attachment-label pull-left">
          <span><strong>{{ item?.file?.name }}({{item?.file?.size | formatBytes}})</strong></span> <i
          class="fa fa-times text-right attachment-delete-button"
          (click)="item.remove()" aria-hidden="true"></i>
        </div>
      </div>
    </div>
  </div>
  </div>
 </div>

无论如何不允许文件夹类型使用 ng2-file-upload 在 chrome 中附加?

任何帮助都会很棒。

4

1 回答 1

0

目前没有官方规定限制文件夹被拖动上传。

https://github.com/valor-software/ng2-file-upload/issues/531

所以我们可以简单地在拖动任何文件夹时恢复状态。

this.uploader.onErrorItem = (error) => {
    /* Show The Popup or Alert with the message saying that Folder Upload is        not allowed and reset the uploader with the below lines.
    */ 
    this.uploader.clearQueue();
    this.uploader.cancelAll();
};

于 2021-10-20T13:54:57.257 回答