O'Reilly logo

Lift Application Development Cookbook by Gilberto T. Garcia Jr.

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Uploading a file using the REST service

We know now how to build a REST API that responds to the basic HTTP methods—GET, POST, PUT, and DELETE. However, we were dealing only with JSON data until now, but what if you also want to allow the users of your application to upload files?

In this recipe, we will learn how to send a file to the server and then save it in the local filesystem.

Getting ready

  1. Create a new project or modify the one we used in the last section.
  2. Edit the index.html file by adding the following form in the div element with main as the value of id:
    <form enctype="multipart/form-data" action="/api/files" method="post"> <fieldset> <legend>New File</legend> <div> <label for="uploadFile">File:</label> <input type="file" id="uploadFile" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required