Luis Trigueiros
2 min readMar 1, 2020

Adding FileUploads to Swagger based API, simple example in Node.JS/Express.JS

Let’s imagine the following common scenario you are developing one app using API first and you want to have self describable self-discoverable API, so you end up using Swagger/OpenApi to provide live documentation of your API.

Next you have been successful in your endeavours you made some releases into production and the customer is using your app and new requirement pop’s in from the customer.

Now the customer would like to have the ability to send file uploads or attachments to your API, how do we go about supporting this requirement ?

Recently I had to implement exactly this, having looked the web unsuccessfully a blog or code example implementing this I decided to do my own and this is a write up to share learnings.

Swagger has support for file upload as documented by the spec at :

And if you are working with Node.JS support for Swagger comes in many forms, but one of the most commons is the:

Bellow is how a very simple ‘/upload’ endpoint would look like:

And the corresponding backing controller code is:

And the associated integration test code:

The complete code example is available at: