我正在使用primeng文件上传
https://www.primefaces.org/primeng/#/fileupload
像这样
<p-fileUpload id="btn_uploadImage" accept="image/*" maxFileSize="2000000"
class="btn btn-primary"
auto="true"
mode="basic"
name="myFile[]" chooseLabel="{{ 'ASSETS.BACKGROUND_IMAGE' | translate}}"
title="{{'ASSETS.CHANGE_BACKGROUND_IMAGE' | translate}}"
[url]="apiImageLocation"
(onUpload)="onUploadImageSuccess($event)" (onError)="onUploadImageError($event)">
</p-fileUpload>
maxFileSize限制起作用。太大的文件将不会上载,但我再也看不到invalidFileSizeMessage。在primeng演示页面上,该消息未在基本模式下显示...
如何显示/翻译无效的文件大小消息?
答案 0 :(得分:0)
您需要使用自定义模式。因为基本模式没有消息内容。 喜欢;
<p-fileUpload name="demo[]" url="./upload.php" (onUpload)="onUpload($event)"
multiple="multiple" accept="image/*" maxFileSize="100">
</p-fileUpload>
这将起作用。
答案 1 :(得分:0)
找到了解决方案
<p-fileUpload #fileUpload
auto="true"
mode="basic"
[url]="apiImageLocation" accept="image/*"
maxFileSize="2097152" (onSelect)="validateFileSize($event, fileUpload.maxFileSize)">
</p-fileUpload>
component.ts
public validateFileSize($event: any, maxFileSize: number): void {
if ($event.files[0].size > maxFileSize) {
this.toastService.errorMessage("Action");
}
}