Search code examples
scalahttptwitter

How do you add a file as a param in scalaj-http for a multipart/form-data request?


I'm trying to use scalaj-http to send an POST request for twitter upload. Ive attached the documentation of what they require for the request. The part I'm having trouble with is trying to pass in the actual binary file as a parameter for "media". I can only seem to see how to do postMulti which is just the file and then add parameter but not actually pass in the data as a parameter.

val appendResponse = Http(twitterApiUrl)
  .postMulti(MultiPart("media", "Output.bin", "application/mac-binary", byteArray))
  .postForm(Seq("command" -> "APPEND", "media_id" -> twitterMediaID, "segment_index" -> "0"))
  .oauth(consumer = consumer, token = access)
  .asString

https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload-append


Solution

  • https://github.com/scalaj/scalaj-http/issues/170

    The fix for the issue is documented on this github issue link