LoopBack — Uploading/Downloading Files

Cris Ferreira Pires
1 min readApr 20, 2021
LoopBack 4

Lets try to get a loopback api that allows for upload and download of files.

After you start an api with lb4 apiname we will get the dependency:

npm i -s @types/multer

Now we need to add 2 controllers with lb4 controller

file — upload and file download:

As we can see it is making reference to some modules we don’t have yet so we need to create them at the root of the src folder.

We also need to add a couple of things into some existing files.

First on the application.ts:

We must add this to the constructor:

Of course never to forget importing the things we need.

Now we must create a new folder on src.

This folder will be called services.

And inside it we will create 2 files, a file-upload.service.ts and a index.ts.

Now we need a way to test it. So we must expose it on a page.

Since its just a test we will use the default page.

So on public/index.html we will change it to the following:

--

--