0

PlayFramework docs shows that it is easy to upload a file.

https://www.playframework.com/documentation/2.5.x/ScalaWS

ws.url(url).post(Source(FilePart("hello", "hello.txt", Option("text/plain"), FileIO.fromFile(tmpFile)) :: DataPart("key", "value") :: List()))

But what if the file content is already in memory? Any alternative method for FileIO.fromFile, such as FileIO.fromString(jsontStr)?

val jsonStr = """{ foo: "Bar"} """
ws.url(url).post(Source(FilePart("hello", "hello.json", Option("application/json"), FileIO.fromString(jsonStr)) :: DataPart("key", "value") :: List()))

1 Answer 1

2

All you need is a FilePart that has a Source[ByteString] as ref. Just use

Source.single(ByteString(jsonStr))

as the ref part.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your quick answer!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.