I\'m following this guys Martin Lasek Tutorials and now i\'m at \"image upload\". It seems that no one has the answer to the question \"How do you upload images i Vapor 3\"
I've managed to get the image data by doing this:
struct ImageRequest: Content {
var imageData: Data
}
func analyizeImage(_ request: Request) throws -> Future {
return try request.content.decode(ImageRequest.self).flatMap(to: Response.self, { [weak self] imageRequest in
guard let image = NSImage(data: imageRequest.imageData) else {
throw Abort(.badRequest)
}
// Do what you want with your image
})
}
My form looked like this: