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.
Create a new project or modify the one we used in the last section.
Edit the
index.html
file by adding the following form in thediv
element withmain
as the value ofid
:<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" name="uploadFile"/> </div> <div> <input type="submit...