Created
August 18, 2016 14:48
-
-
Save j4y/76bd376afa36382c3f1bad82f2e93d0a to your computer and use it in GitHub Desktop.
This file contains 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
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.2') | |
@Grab(group='org.apache.httpcomponents', module='httpclient', version='4.3.5') | |
@Grab(group='org.apache.httpcomponents', module='httpmime', version='4.3.5') | |
import groovyx.net.http.* | |
import groovyx.net.http.HTTPBuilder | |
import static groovyx.net.http.Method.POST | |
import org.apache.http.entity.mime.MultipartEntityBuilder | |
import org.apache.http.entity.mime.content.ByteArrayBody | |
import org.apache.http.entity.mime.content.StringBody | |
import org.apache.http.entity.mime.content.FileBody | |
def http = new HTTPBuilder("http://localhost:8080") | |
http.request (POST) { multipartRequest -> | |
uri.path = '/app/sessions' | |
MultipartEntityBuilder multipartRequestEntity = new MultipartEntityBuilder() | |
String key = | |
multipartRequestEntity.addPart('faceVideoToken', new StringBody(java.util.UUID.randomUUID() as String)) | |
multipartRequestEntity.addPart('key', new StringBody('blah')) | |
multipartRequestEntity.addPart('videoData', new FileBody(new File('/Users/jprall/Desktop/big-file.txt'))) | |
multipartRequest.entity = multipartRequestEntity.build() | |
response.success = { resp, data -> | |
print 'success' | |
print data | |
} | |
response.failure = { resp, data -> | |
print 'fail' | |
print data | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment