API File Upload Angular Express Backend

This article is for you if * You want to upload a file from the client side via API (I’m doing via Angular. You can do same anywhere * You want to receive the uploaded file from the client side via API in your backend (Express)

Here we go. Stay with me. I’m writing this article out of frustration of how vast information on the internet is, yet none makes the most, minimal, barebone sense (sometimes).

Let’s start with the form

The File Input

When the uploadFile(...) is triggered, we handle that in the component like so:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

uploadFile(files){

constformDataForm=newFormData();

myForm.append('toUpload',files[0]);// the toUpload is the name of the file. You can call it anything you like