I want to upload a file in my form. However, currently I only manage to do this separately.
def upload = Action(parse.multipartFormData) { request =>
request.body
.file("picture")
.map { picture =>
// only get the last part of the filename
// otherwise someone can send a path like ../../home/foo/bar.txt to write to other files on the system
val filename = Paths.get(picture.filename).getFileName
val fileSize = picture.fileSize
val contentType = picture.contentType
picture.ref.copyTo(Paths.get(s"pictures/$filename"), replace = true)
Ok("File uploaded")
}
.getOrElse {
...
}
}
@helper.form(action = routes.PostController.upload, Symbol("enctype") -> "multipart/form-data") {
@CSRF.formField
<input type="file" name="picture">
<p>
<input type="submit">
</p>
}
Is there a way to add this to another form so that you can submit one form instead of having to submit an extra form for the upload?
Thanks in advance!