我在使文件上传正常工作时遇到一些问题,并且以下代码无法编译。
错误:overloaded method constructor File with alternatives: (java.net.URI)java.io.File <and> (java.lang.String)java.io.File cannot be applied to (play.api.mvc.MultipartFormData.FilePart[play.api.libs.Files.TemporaryFile])
代码:
def csvimport = Action(parse.multipartFormData) { request =>
request.body.file("files[]").map { rawfile =>
val filename = rawfile.filename
val contentType = rawfile.contentType
val tmpFile = new File(rawfile)
val reader = new CSVReader(new FileReader(tmpFile))
Ok
}
.getOrElse {
Logger.debug(request.body.toString)
BadRequest
}
}
File
类?最佳答案
这是我想您要达到的目标
https://stackoverflow.com/a/11059295/317452
https://gist.github.com/2939230
这将逐步解析文件的大块,而不会将整个原始文件放入内存或磁盘中。
https://stackoverflow.com/questions/11147489/