Vapor allows you to upload files using Multipart encoding. You can learn more about downloading HTTP here:
How does uploading an HTTP file work?
And also here:
What does enctype = 'multipart / form-data' mean?
So, the HTML code for uploading a file to Vapor will look something like this:
<form action="upload" method="POST" enctype="multipart/form-data"> <input type="text" name="name"> <input type="file" name="image"> <input type="submit" value="Submit"> </form>
And then the code in Vapor
drop.get("form") { req in return try drop.view("form.html") } drop.post("upload") { req in let name = req.data["name"] let image = req.data["image"]
In terms of image storage, it is up to you. You can save to the database or create a folder in the system to which you have write access.
tanner0101
source share