gpt4 book ai didi

html - 如何从 prime ng p-fileUpload 的文件上传中删除无效或特定文件?

转载 作者:太空狗 更新时间:2023-10-29 18:28:42 26 4
gpt4 key购买 nike

我已使用文件上传来上传文件,我想在选择其中一个文件时验证文件,如果该文件不是有效文件,则将其删除。

.html

<p-fileUpload #fileUpload  name="datafiles"
[accept]=FileExtentionValue
[url]="FileUploadUrl"
[showUploadButton]="isUploadEnable"
[disabled]="diableFileupload"
(onUpload)="onUpload($event)"
(onSelect)="validateFile($event)"
multiple="multiple">
</p-fileUpload>

.ts

onUpload(event) {
for (let file of event.files) {
this.uploadedFiles.push(file);
}
this.messageService.add({ severity: 'info', summary: 'File Uploaded', detail: '' });
}

验证女孩的名字

     validateFile(event) {
let tempFiles: any = [];
var FileNmaeMust: any;
for (let file of event.files) {
tempFiles.push(file.name);
}
for (let i = 0; i < tempFiles.length; i++) {
let count = 1;
for (let j = 0; j < this.ClientDataFileTypeValue.length; j++) {
FileNmaeMust = "";
if (this.ClientDataFileTypeValue[j] == "Order") {
FileNmaeMust = this.MPID + "_ORDER_";
}
/*** Validate File */
var templen = FileNmaeMust + "YYYYMMDD.psv";
if (tempFiles[i].includes((FileNmaeMust).toLocaleUpperCase()) && tempFiles[i].length == templen.length) {
this.isUploadEnable = true;
break;
}
if (count == this.ClientDataFileTypeValue.length) {
this.isUploadEnable = false;
this.messageService.add({ severity: 'error', summary: 'Files', detail: 'Please select correct file ' + tempFiles[i] });
}
count++;
}
}
}

最佳答案

我已经使用 id 对它进行了保存。我已经定义了 #fileUpload 并将其传递给 (onSelect)="validateFile($event,fileUpload)" 函数来验证和从数组中删除此文件。

<p-fileUpload #fileUpload name="datafiles" 
[accept]=FileExtentionValu
[url]="FileUploadUrl"
[disabled]="isDiableFileupload"
[showUploadButton]="isUploadEnable"
(onSelect)="validateFile($event,fileUpload)" (onBeforeUpload)="onBeforeSend($event)"
(onUpload)="onUpload($event)"
multiple="multiple">
</p-fileUpload>

.ts

import {FileUpload } from 'primeng/primeng';

validateFile(event, uploader: FileUpload) {
let tempFiles: any = [];
var FileNmaeMust: any;
for (let file of event.files) {
tempFiles.push(file.name);
}
for (let i = 0; i < tempFiles.length; i++) {
let count = 1;
for (let j = 0; j < this.ClientDataFileTypeValue.length; j++) {
FileNmaeMust = "";
if (this.ClientDataFileTypeValue[j] == "Order") {
FileNmaeMust = this.MPID + "_ORDER_";
}
/*** Validate File */
var templen = FileNmaeMust + "YYYYMMDD.psv";
if (tempFiles[i].includes((FileNmaeMust).toLocaleUpperCase()) && tempFiles[i].length == templen.length) {
this.isUploadEnable = true;
break;
}
if (count == this.ClientDataFileTypeValue.length) {
this.isUploadEnable = false;
uploader.remove(event, i);
this.isUploadEnable = true;
this.messageService.add({ severity: 'error', summary: 'Files', detail: 'Please select correct file ' + tempFiles[i] });
}
count++;
}
}
}

关于html - 如何从 prime ng p-fileUpload 的文件上传中删除无效或特定文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52511892/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com