Created
August 28, 2015 17:09
-
-
Save brianwawok/eb9ac542eb7b4795ac06 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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