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.
index.htmlfile by adding the following form in the
mainas the value of
<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" ...