Ich bin derzeit versucht, eine Datei zu einem Endpunkt posten die WSClient verwenden, mit dem folgenden CodePosting MultipartFormData mit dem 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();
}
}
Ich bin mit der Framework-Version 2.5.15 und mit Java 8 . Das Problem, das ich bin immer ist
/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 -
ich bin nicht sicher, wie dieses Problem zu lösen. Wenn mir jemand in die richtige Richtung zeigen könnte, wäre das sehr geschätzt. Danke
Das war in der Tat mein Problem, danke für Ihre Hilfe. – Ergun
Gern geschehen! kannst du die antwort einfach annehmen;)? –