Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何使用ngx uploader仅上载非重复文件_Angular_Typescript_Ngx Uploader - Fatal编程技术网

Angular 如何使用ngx uploader仅上载非重复文件

Angular 如何使用ngx uploader仅上载非重复文件,angular,typescript,ngx-uploader,Angular,Typescript,Ngx Uploader,如何使用ngx uploader仅上载非重复文件? 我看不到上传时有任何不同文件名的选项?这可以通过一些代码来处理,但不能破坏UI吗? 文件被添加到队列中,然后按其状态进行处理。我还想直接上传它(如果您想在添加时自动上传文件,请参阅//取消注释) 从'@angular/core'导入{Component,EventEmitter}; 从“ngx uploader”导入{UploadOutput、UploadInput、UploadFile、Ebytes、UploaderOptions}; @组成

如何使用ngx uploader仅上载非重复文件? 我看不到上传时有任何不同文件名的选项?这可以通过一些代码来处理,但不能破坏UI吗? 文件被添加到队列中,然后按其状态进行处理。我还想直接上传它(如果您想在添加时自动上传文件,请参阅//取消注释)

从'@angular/core'导入{Component,EventEmitter};
从“ngx uploader”导入{UploadOutput、UploadInput、UploadFile、Ebytes、UploaderOptions};
@组成部分({
选择器:“应用程序主页”,
templateUrl:'app home.component.html'
})
导出类AppHomeComponent{
选项:上传选项;
formData:formData;
文件:上传文件[];
上传输入:EventEmitter;
人源性细胞:功能;
德拉戈弗:布尔;
构造函数(){
this.options={concurrency:1,maxUploads:3,maxFileSize:1000000};
this.files=[];//本地上载文件数组
this.uploadInput=new EventEmitter();//输入事件,我们使用它向ngx uploader发送数据
this.humanizeBytes=humanizeBytes;
}
onUploadOutput(输出:上传输出):void{
开关(输出类型){
案例“allAddedToQueue”:
//如果要在添加文件时自动上载文件,请取消对此的注释
常量事件:上载输入={
键入:“uploadAll”,
url:“/upload”,
方法:“POST”,
数据:{foo:'bar'}
};
this.uploadInput.emit(事件);
打破
案例“addedToQueue”:
if(typeof output.file!=“未定义”){
this.files.push(output.file);
}
打破
“上传”案例:
if(typeof output.file!=“未定义”){
//更新文件数组中的当前数据以上载文件
const index=this.files.findIndex(file=>typeof output.file!=='undefined'&&file.id===output.file.id);
this.files[index]=output.file;
}
打破
“删除”案例:
//删除时从阵列中删除文件
this.files=this.files.filter((文件:UploadFile)=>file!==output.file);
打破
“德拉戈弗”案:
this.dragOver=true;
打破
“排水沟”案例:
“放弃”案例:
this.dragOver=false;
打破
案例“完成”:
//该文件已下载
打破
}
}
startUpload():无效{
常量事件:上载输入={
键入:“uploadAll”,
网址:'http://ngx-uploader.com/upload',
方法:“POST”,
数据:{foo:'bar'}
};
this.uploadInput.emit(事件);
}
碰撞

import { Component, EventEmitter } from '@angular/core';
import { UploadOutput, UploadInput, UploadFile, humanizeBytes, UploaderOptions } from 'ngx-uploader';
 
@Component({
  selector: 'app-home',
  templateUrl: 'app-home.component.html'
})
export class AppHomeComponent {
  options: UploaderOptions;
  formData: FormData;
  files: UploadFile[];
  uploadInput: EventEmitter<UploadInput>;
  humanizeBytes: Function;
  dragOver: boolean;
 
  constructor() {
    this.options = { concurrency: 1, maxUploads: 3, maxFileSize: 1000000 };
    this.files = []; // local uploading files array
    this.uploadInput = new EventEmitter<UploadInput>(); // input events, we use this to emit data to ngx-uploader
    this.humanizeBytes = humanizeBytes;
  }
 
  onUploadOutput(output: UploadOutput): void {
    switch (output.type) {
      case 'allAddedToQueue':
         // uncomment this if you want to auto upload files when added
         const event: UploadInput = {
           type: 'uploadAll',
           url: '/upload',
           method: 'POST',
           data: { foo: 'bar' }
         };
         this.uploadInput.emit(event);
        break;
      case 'addedToQueue':
        if (typeof output.file !== 'undefined') {
          this.files.push(output.file);
        }
        break;
      case 'uploading':
        if (typeof output.file !== 'undefined') {
          // update current data in files array for uploading file
          const index = this.files.findIndex(file => typeof output.file !== 'undefined' && file.id === output.file.id);
          this.files[index] = output.file;
        }
        break;
      case 'removed':
        // remove file from array when removed
        this.files = this.files.filter((file: UploadFile) => file !== output.file);
        break;
      case 'dragOver':
        this.dragOver = true;
        break;
      case 'dragOut':
      case 'drop':
        this.dragOver = false;
        break;
      case 'done':
        // The file is downloaded
        break;
    }
  }
 
  startUpload(): void {
    const event: UploadInput = {
      type: 'uploadAll',
      url: 'http://ngx-uploader.com/upload',
      method: 'POST',
      data: { foo: 'bar' }
    };
 
    this.uploadInput.emit(event);
  }