将图片(ctrl + v)粘贴到ngx-dropzone

时间:2020-08-25 13:35:03

标签: node.js angular image-upload

是否可以将图像粘贴到ngx-dropzone angular模块的放置区域中?

我可以以某种方式向其中添加(paste)事件吗?

ngx-dropzone


        <div class="custom-dropzone" ngx-dropzone [accept]="'image/*'" (change)="onSelect($event)">
            <ngx-dropzone-label>
                <div>
                    <h2>Drop image here</h2>
                </div>
            </ngx-dropzone-label>
            <ngx-dropzone-image-preview ngProjectAs="ngx-dropzone-preview" *ngFor="let f of files" [file]="f" [removable]="true" (removed)="onRemove(f)">
                <ngx-dropzone-label>{{ f.name }} ({{ f.type }})</ngx-dropzone-label>
            </ngx-dropzone-image-preview>
        </div>

1 个答案:

答案 0 :(得分:0)

找到粘贴事件的方法:

  onPaste(event: any) {
    const items = (event.clipboardData || event.originalEvent.clipboardData).items;
    let blob = null;

    for (const item of items) {
      if (item.type.indexOf('image') === 0) {
        blob = item.getAsFile();
      }
    }
    this.files.push(blob); // insert to ngx-drop files array