Skip to content

Instantly share code, notes, and snippets.

@brianwawok
Created August 28, 2015 17:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianwawok/eb9ac542eb7b4795ac06 to your computer and use it in GitHub Desktop.
Save brianwawok/eb9ac542eb7b4795ac06 to your computer and use it in GitHub Desktop.
// this works in play 2.4 with the 1.9.29 version of async http client
def securePostMultipart(requestPath: String, etsyToken: RequestToken,
fileName: String, file: File, fileMimeType: String,
stringParts: (String, String)*): Future[WSResponse] = {
val fullUrl = "http://foo/bar/zar"
val parts : List[Part] = List(
new FilePart(fileName, file, fileMimeType),
new StringPart("type", fileMimeType)
)
val mpre = new MultipartRequestEntity(parts.asJava, new FluentCaseInsensitiveStringsMap)
val baos = new ByteArrayOutputStream(5 * 1024 * 1024)
mpre.writeRequest(baos)
val bytes = baos.toByteArray
makeEtsyApiCall(
() => WS.url(fullUrl)
.sign(OAuthCalculator(etsyKey, etsyToken))
.withRequestTimeout(etsyApiCallTimeout)
.withHeaders("Accept" -> "application/json", "Content-Type" -> mpre.getContentType)
.withQueryString(stringParts: _*)
.post(bytes)(Writeable.wBytes)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment