Our file upload tests look something like this:
val tempFile = TemporaryFile(new java.io.File("/tmp/the.file")) val part = FilePart[TemporaryFile](key = "image", filename = "the.file", contentType = Some("image/jpeg"), ref = tempFile) val formData = MultipartFormData(dataParts = Map(), files = Seq(part), badParts = Seq(), missingFileParts = Seq()) val result = routeAndCall(FakeRequest(POST, "/path/to/test", FakeHeaders(), formData))
where "image" is the name of the HTML form element in which you expect to find the contents of the file.
If you use BodyParsers.maxLength to limit download size, you can replace formData with Right(formData)
source share