1
我目前正在使用WSClient發佈文件到終點,用下面的代碼用java
public Result uploadBankingFile(){
logger.info("Uploading file to cold fusion");
MultipartFormData<File> body = request().body().asMultipartFormData();
MultipartFormData.FilePart<File> bankingFile = body.getFile("bankingFile");
if (bankingFile != null) {
String fileName = bankingFile.getFilename();
String contentType = bankingFile.getContentType();
//field needs to be called import
Source<ByteString, ?> file = FileIO.fromFile(bankingFile.getFile());
MultipartFormData.FilePart<Source<ByteString, ?>> fp = new MultipartFormData.FilePart<>("import", fileName, "text/plain", file);
MultipartFormData.DataPart dp = new MultipartFormData.DataPart("key", "value");
Future<WSResponse> post = ws.url(coldFusionPath + coldFusionUploadPath).post(Source.from(Arrays.asList(fp,dp)));
return new JsonResult("ok");
} else {
flash("error", "Missing file");
return badRequest();
}
}
我使用的框架版本2.5.15,並與Java 8發佈MultipartFormData與WSClient 。我得到的問題是
/ImportBankingData.java:58: no suitable method found for post(akka.stream.javadsl.Source<play.mvc.Http.MultipartFormData.Part<akka.stream.javadsl.Source<akka.util.ByteString,?>>,akka.NotUsed>)
[error] method play.api.libs.ws.WSRequest.<T>post(T,play.api.http.Writeable<T>) is not applicable
[error] (cannot infer type-variable(s) T
[error] (actual and formal argument lists differ in length))
[error] method play.api.libs.ws.WSRequest.post(java.io.File) is not applicable
[error] (argument mismatch; no instance(s) of type variable(s) O,T exist so that akka.stream.javadsl.Source<O,akka.NotUsed> conforms to java.io.File)
[error] method play.api.libs.ws.WSRequest.post(akka.stream.scaladsl.Source<play.api.mvc.MultipartFormData.Part<akka.stream.scaladsl.Source<akka.util.ByteString,?>>,?>) is not applicable
[error] (argument mismatch; no instance(s) of type variable(s) O,T exist so that akka.stream.javadsl.Source<O,akka.NotUsed> conforms to akka.stream.scaladsl.Source<play.api.mvc.MultipartFormData.Part<akka.stream.scaladsl.Source<akka.util.ByteString,?>>,?>)
[error] ws.url(coldFusionPath + coldFusionUploadPath).post
[error] (compile:compileIncremental) javac returned nonzero exit code
[info] Compiling 1 Java source to /Users/ergun/Documents/projects/brightbook/web/target/scala-2.11/classes...
[error] /Users/ergun/Documents/projects/brightbook/web/app/co/brightbook/web/controllers/ImportBankingData.java:58: no suitable method found for post(akka.stream.javadsl.Source<play.mvc.Http.MultipartFormData.Part<akka.stream.javadsl.Source<akka.util.ByteString,?>>,akka.NotUsed>)
[error] method play.api.libs.ws.WSRequest.<T>post(T,play.api.http.Writeable<T>) is not applicable
[error] (cannot infer type-variable(s) T
[error] (actual and formal argument lists differ in length))
[error] method play.api.libs.ws.WSRequest.post(java.io.File) is not applicable
[error] (argument mismatch; no instance(s) of type variable(s) O,T exist so that akka.stream.javadsl.Source<O,akka.NotUsed> conforms to java.io.File)
[error] method play.api.libs.ws.WSRequest.post(akka.stream.scaladsl.Source<play.api.mvc.MultipartFormData.Part<akka.stream.scaladsl.Source<akka.util.ByteString,?>>,?>) is not applicable
[error] (argument mismatch; no instance(s) of type variable(s) O,T exist so that akka.stream.javadsl.Source<O,akka.NotUsed> conforms to akka.stream.scaladsl.Source<play.api.mvc.MultipartFormData.Part<akka.stream.scaladsl.Source<akka.util.ByteString,?>>,?>)
[error] ws.url(coldFusionPath + coldFusionUploadPath).post
[error] (compile:compileIncremental) javac returned nonzero exit code
[error] application -
我不知道如何解決此問題。如果任何人都可以指出我正確的方向,將不勝感激。謝謝
這確實是我的問題,謝謝你的幫助。 – Ergun
不客氣!你能接受答案嗎?)? –