Uploading Files! Multipart form-data in Loopback

Tyson Javier Cardelli Muñoz
nemobile
Published in
1 min readNov 19, 2019

Hi!

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:

--

--

Tyson Javier Cardelli Muñoz
nemobile
Writer for

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