HTML page
<nz-upload
nzAccept="application/pdf,image/jpeg,image/jpg,image/png"
[(nzFileList)]="fileList"
[(nzAction)]="UPLOAD_FILE"
[nzShowButton]="fileList.length < 1"
[nzBeforeUpload]="beforeUpload"
(nzChange)="getFileUrl($event)" >
<button nz-button>
<i nz-icon nzType="upload"></i>
<span>upload files</span>
</button>
</nz-upload>
TS file
import { Component, OnInit } from '@angular/core';
import { NzMessageService, NzModalService, UploadFile } from 'ng-zorro-antd';
@Component({
selector: 'app-detail',
templateUrl: './detail.component.html',
styleUrls: ['./detail.component.scss']
})
export class DetailComponent implements OnInit {
UPLOAD_FILE = ''; // File upload path
constructor(
private activeRoute: ActivatedRoute,
private msg: NzMessageService,
private router: Router,
private message: NzModalService,
){ }
fileList: UploadFile[] = [];
beforeUpload = (file: UploadFile): boolean => {
// Judgment on the upload file type
const type = file.type;
const str = ['application/pdf', 'image/jpg', 'image/jpeg', 'image/png'];
if (str.indexOf(type) < 0) {
this.message.warning({
nzTitle: 'Warning',
nzContent: 'Select file failed, only pdf, jpg, jpeg, png and other formats are supported'
});
return false;
}
// Limit on upload file size
const isLt20M = file.size / 1024 / 1024 < 30;
if (!isLt20M) {
this.message.warning({
nzTitle: 'Warning',
nzContent: 'The file must be less than 30M'
});
return false;
}
this.fileList = this.fileList.concat(file);
// When the type and size meet the requirements, upload directly; if return false, then you need to call the upload method manually
return true;
}
// Method to get the path when the file upload is finished
getFileUrl({ file, fileList }): void {
const status = file.status;
if (status === 'done') {
this.zizhi_prove = file.response.data
} else if (status === 'error') {
this.msg.error(`${file.name} file upload failed.`);
}
}
}
Read More:
- Ant Design upload listtype = “picture card” realizes multi image upload and click preview image encapsulation
- Winscp failed to upload the file to the server, indicating permission denied with return code 3
- Mac realizes file interaction (upload and download) between terminal and server
- PHP big file upload problem (500m or above)
- GitHub desktop upload file error commit failed – exit code 1 received
- Image file upload error org.springframework.beans .ConversionNotSupportedException
- Spring MVC realizes page upload file
- Ueditor paste word image and upload image file automatically
- [Solved] IE Browser Upload Files Error: org.apache.tomcat.util.http.fileupload.FileUploadException: Stream ended unexpectedly
- Error: ENOENT: no such file or directory, open ‘E:\Program Files\nodejs\tmp\upload_38b32f25bc984333c
- Java – read all the files and folders in a certain directory and three methods to get the file name from the file path
- move_uploaded_file() failed to open stream: Permission denied
- An idea to solve Warning move_uploaded_file, failed to open stream in the process of php uploading files
- C#: How to Use Httpclient to upload files with other parameters
- Securityerror: error ᦇ 2148: SWF file XXX cannot access local resources, only file system only
- Git push you are not allowed to upload merges
- Vue introduction path is correct, but it always reports an error: already included file name‘ ××ב differs from file name ‘ ××ב only in casing.
- Nginx upload error 413 request entity too large
- Failed to upload report – An error has occurred. Please contact your administrator
- curl: (25) Failed FTP upload: 550 Solution