Some applications allow the user to upload files. Even for the note application, it might be useful to attach a file to a note. To upload a file, you integrate an input field of the file
type into your form. If you submit the form, then the form data and the file must be transmitted to the server. You need to use the POST
method and the multipart/form-data
encoding to make this work. On the server side, the files
member contains the original filename and the path of the uploaded file. The member works as an associative array. The key is the name of the input field in the form.
Let's create an application to demonstrate this, as shown in the following:
Create a new project with
dub
:$ dub init upload --type=vibe.d
Create a
index.dt
template in theviews
folder. It contains a simple form with an input field to select a file:doctype html head title File upload body form(method='post',action='/upload',enctype='multipart/form-data') p label(for='filename') File ...