use of io.videofirst.capture.http.ProgressListener in project vft-capture by videofirst.
the class DefaultUploadService method getHttpPost.
/**
* Prepare HTTP Post upload call
*/
private HttpPost getHttpPost(Capture capture) {
// Get capture file and data file
File videoFile = validateExists(capture.getVideoFile());
File dataFile = validateExists(capture.getDataFile());
HttpPost httpPost = new HttpPost(uploadConfig.getUrl());
uploadConfig.getHeaders().entrySet().stream().forEach(e -> httpPost.setHeader(e.getKey(), e.getValue()));
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addBinaryBody(PARAM_VIDEO, videoFile, ContentType.DEFAULT_BINARY, videoFile.getName());
builder.addBinaryBody(PARAM_DATA, dataFile, ContentType.DEFAULT_BINARY, dataFile.getName());
HttpEntity multipart = builder.build();
ProgressListener pListener = new VideoUploadProgressListener(captureDao, capture, DAO_UPDATE_INTERVAL_MILLIS);
httpPost.setEntity(new ProgressEntityWrapper(multipart, pListener));
return httpPost;
}
use of io.videofirst.capture.http.ProgressListener in project vft-capture by videofirst.
the class MockUploadController method main.
/**
* Manually hit an end-point.
*/
public static void main(String[] args) throws IOException {
String dir = "src/test/resources/videos/acme/moon-rocket/ui/bob-feature/dave-scenario/2018-02-15_12-14-02_n3jwzb/";
File videoFile = new File(dir + "2018-02-15_12-14-02_n3jwzb.avi");
File dataFile = new File(dir + "2018-02-15_12-14-02_n3jwzb.json");
CloseableHttpClient client = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("http://localhost:1357/mock-upload");
httpPost.setHeader("Authorization", "Basic dGVzdDpwYXNzd29yZA==");
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addBinaryBody("video", videoFile, ContentType.DEFAULT_BINARY, videoFile.getName());
builder.addBinaryBody("data", dataFile, ContentType.DEFAULT_BINARY, dataFile.getName());
HttpEntity multipart = builder.build();
ProgressListener pListener = (transferredBytes, totalBytes) -> System.out.println("transferredBytes [ " + transferredBytes + " ] , totalBytes [ " + totalBytes + " ] ");
httpPost.setEntity(new ProgressEntityWrapper(multipart, pListener));
System.out.println("Posting");
CloseableHttpResponse response = client.execute(httpPost);
System.out.println(response.getStatusLine().getStatusCode());
client.close();
System.out.println("Done");
}
Aggregations