Uploading Files! Multipart form-data in Loopback


In this short article I’m going to explain how is possible upload multipart form-data in loopback.

Maybe you’re looking for how send files via Post Request in loopback, in the official documentation there isn’t a clear reference for that.

Let’s check the following:

Multer package

We’re going to use multer, Multer is a nodeJS package for handling multipart form-data: https://www.npmjs.com/package/multer

You can install using npm i multer or yarn add multer depend of the case.

Multer is going to add a body object or a file object to request.

Then, if you alredy installed multer now you can add the logic to your controller:

Don’t forget import above of this way:

import multer = require(‘multer’);import {   RestBindings,   Request,   Response,} from ‘@loopback/rest’;

Now you only have to use the object request.files and request.fields to see the info of the file, something like that:


Empowering businesses to new heights

Tyson Javier Cardelli Muñoz

Written by

Hi! I’m passionate for knowledge, I love writting and share everything that I learn.



Empowering businesses to new heights

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade