I am using PrimeNG uploader for upload files. I want to do validation if the file size is less than 1kb. There is no properties for min File size.
HTML
<p-fileUpload multiple="true" mode="advanced" name="parseFileData[]" #fileInput
accept=".kmz" maxFileSize="12582912" chooseLabel="Browse File"></p-fileUpload>
CodePudding user response:
Please find the approach, this might help you to achieve minimum file size upload validation using p-fileUpload:
sample.component.html
<p-fileUpload customUpload="true" (uploadHandler)="onFileUpload($event)"></p-fileUpload>
You can validate the file size in the component when the file gets uploaded like below:
sample.component.ts
onFileUpload(event) {
let fileSize = event.files[0].size; // you will get the uploaded file size
if (fileSize > 1000) {
console.log("File size is Greater than 1KB");
// logic goes here for file uploaded greater than 1KB
}
}
CodePudding user response:
(onBeforeUpload) -> event.formData: FormData object. -> Callback to invoke before file upload is initialized.
The doc says like this. You can check the file size from the FormData, before uploading it.