I am trying to post pdf file to external service with multipart/form-data request. I've done this with sample Java Script client so the external service works properly. Hovewer in scala with the following code I got: 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()
))
Play version: 2.6.19
Following curl command upload the file properly:
curl -X POST "https://rest_url" -H "accept: */*" -H "Authorization: bearer <TOKEN>" -H "Content-Type: multipart/form-data" -F "File=@sampleCV.pdf;type=application/pdf"
Did I miss some important parameter in post(...)
? What are appropriate post parameters in ScalaWS which corresponds to this CURL request?