【发布时间】:2022-10-21 21:15:37
【问题描述】:
我正在尝试使用此代码上传文件
onDrag(event:any) {
console.log(this.toUpload);
if(this.toUpload.length >0){
this.error = "Only one file at the time is accepted";
}else{
let fileName = event[0].name;
let split = fileName.split(".");
let ext = split[split.length - 1].toLowerCase();
if(ext !="xlsx" && ext!="xls" ){
this.error = "Only xls or xlsx files are supported";
}else{
if(event[0].size > 28000000){
this.error = "the file is too big"
}else{
this.toUpload.push(event[0]);
this.error = null;
}
}
}
console.log(this.toUpload);
}
<div class="dropzone my-3"
(click)="fileInput.click()" appDragdrop (onFileDropped)="onDrag($event)">
<input hidden accept=".xls,.xlsx" type="file" #fileInput (change)="onDrag($any($event).target.files);">
<img src="assets/img/dnd/ic-upload-file.svg" alt="" />
<h3>Aggiungi Registro</h3>
斯福利亚...
我有两个问题
第一个不太重要的是拖放不起作用
我真正需要解决的一个问题是,如果我通过navigate files 选择一个文件,选择File.xlsx 并按下删除按钮,它会从事件[] 中正确删除,但我无法再次上传相同的文件.如果我更改文件它可以工作,只要我不删除它
当这种情况发生时,我什至无法到达第一个 console.log(),所以它基本上不会进入方法内部
当我刷新页面时,一切都会再次起作用
正确上传后,文件会发送到后端并正确处理...所以我认为这不是与文件相关的问题
我能做些什么?
【问题讨论】:
标签: html angular typescript file-upload