This is the code in scala how can we do a similar thing in java using the play framework reference: -> Play WS - post multipart/form-data from scala - Bad Request
import akka.stream.scaladsl.FileIO
import akka.stream.scaladsl.Source
import play.api.libs.ws.WSClient
import play.api.mvc.MultipartFormData._
val pathToFile = "./sampleCV.pdf"
val fileName = "sampleCV.pdf"
val futureResponse = ws.url(url).withRequestTimeout(Duration.create(55, TimeUnit.SECONDS))
.addHttpHeaders("authorization" -> s"bearer $access_token")
.addHttpHeaders("accept" -> "*/*")
.addHttpHeaders("content-type" -> "multipart/form-data")
.post(Source(
FilePart("File", fileName, Option("application/pdf"), FileIO.fromPath(Paths.get(pathToFile))) :: List()
))
I had tried but got 412 as the response code as I was using an HTTP multipart file.