Skip to content

Commit 00d9b65

Browse files
author
Your Name
committed
Angular Forms In Depth
1 parent bb95407 commit 00d9b65

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/app/file-upload/file-upload.component.ts

+34-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ export class FileUploadComponent {
1717

1818
fileName = '';
1919

20+
fileUploadError = false;
21+
22+
constructor(private http: HttpClient) {
23+
24+
}
25+
2026
onFileSelected(event) {
2127

2228
const file:File = event.target.files[0];
@@ -25,10 +31,37 @@ export class FileUploadComponent {
2531

2632
this.fileName = file.name;
2733

28-
console.log(this.fileName);
34+
const formData = new FormData();
35+
36+
formData.append("thumbnail", file);
37+
38+
this.fileUploadError = false;
39+
40+
this.http.post("/api/thumbnail-upload", formData)
41+
.pipe(
42+
catchError(error => {
43+
this.fileUploadError = true;
44+
return of(error);
45+
})
46+
)
47+
.subscribe();
48+
49+
2950

3051
}
3152

3253
}
3354

3455
}
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+

0 commit comments

Comments
 (0)