Created
September 11, 2022 00:14
-
-
Save sunnyy02/9d3e47c3e8274469a64a105afa0a1478 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
attachFile(event: any) { | |
const file: File = event.target.files?.[0]; | |
if (file && this.isValid(file)) { | |
this.errorMessage = ''; | |
const formData = new FormData(); | |
formData.append('file', file, file.name); | |
const uploadFileHeaders = new HttpHeaders({ | |
Accept: `application/json, text/plain, */*`, | |
}); | |
this.httpClient | |
.post('/api/file-upload/upload', formData, { | |
headers: uploadFileHeaders, | |
}) | |
.subscribe({ | |
next: (response) => { | |
this.successMessage = `Document ${file.name} is uploaded successfully`; | |
}, | |
error: (error) => { | |
this.errorMessage = `failed to upload document.`; | |
return error; | |
}, | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment