gedochao
gedochao

Reputation: 51

Play standalone WS client is unable to upload multipart files without importing the core play framework jar

using the play-ws-standaloneplay-ws-standalone version 2.1.2

I am using the play standalone ws client to make rest calls in my Scala project. In the particular part of my codebase where I have the problem, I do not import the core play framework jar (and neither do I want to, the standalone ws client should not need it).

What I have a problem with is sending a post request with a multipart file. According to the example, I should use play.api.mvc.MultipartFormData.FilePart[Source[ByteString, Any]], which is in the core Play framework jar (unlike all other classes relevant to the ws client, which can be found in the play-ws-standalone jar).

DefaultBodyWritables only provide a BodyWritable implementation for uploading a single File: DefaultBodyWritables.writableOf_File, so it doesn’t suit my purpose.

I understand that I could implement my own BodyWritable for multipart/form-data media type, but unsure how to make it work. the MultiPartFormData implementation in Play framework is quite complex. Any tips on this would be helpful.

TLDR;

Are there any reasons why FilePart cannot be decoupled from the Play framework? Is there any workaround that would save me from importing the whole framework in this module (which I’d really prefer to avoid) for uploading multipart/form-data with the play-ws-standalone?

Upvotes: 4

Views: 197

Answers (0)

Related Questions