Skip to main content

Rest API - Download Test Video

The Reporter provides you with a Rest API that gives you direct access to the test data and statistics.

Download Test Video​

You can download the Video report video as an MP4 file using these methods (provided there is a video to download).

  • This API is available for all user roles with permission to access the desired project.
GET /reporter/api/tests/<id>/video?download=Y

Code Example​

The examples below using the Unirest HTTP library.  To compile and run them, use the following Maven dependency:

Maven Dependency

<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.9</version>
</dependency>

Java Expand source

import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import org.apache.http.HttpHeaders;
import org.junit.Test;

import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;

public class APIConfluenceDownloadVideo {
private HttpResponse<String> responseString;

private HttpResponse<InputStream> responseInputStream;

private String urlBase = "http://hostname:port/"; //TODO: modify hostname and port of your Reporter
private String accessKey= "....."; //TODO: user access key
private String testID = "test ID";//TODO: test ID is here



@Test
public void testFullDownloadWithExistingTestByParts() throws UnirestException, IOException {
String downloadDestination = "<File path including file name on your file system. e.g. /temp/newFile.mp4>"; //TODO: modify file path
downloadVideoFileByParts(testID, downloadDestination);
}

public ContentRange downloadVideoBytes(String managerTestId, FileOutputStream out, long start, long end) throws UnirestException, IOException {
final String url = String.format("%s/api/tests/%s/video", urlBase, managerTestId);
HttpResponse<InputStream> responseString = Unirest.get(url)
.header(HttpHeaders.AUTHORIZATION, "Bearer " + accessKey)
.header(HttpHeaders.RANGE, "bytes=" + start + "-" + end)
.asBinary();
InputStream in = responseString.getBody();
byte[] readBytes = new byte[1024];
while(in.read(readBytes) != -1) {
out.write(readBytes);
}
return new ContentRange(responseString.getHeaders().getFirst("Content-Range"));
}

private void downloadVideoFileByParts(String managerTestId, String downloadDestination) throws UnirestException, IOException {
Path downloadFile = Paths.get(downloadDestination);
if (Files.notExists(downloadFile.getParent())) {
Files.createDirectories(downloadFile.getParent());
}
try(FileOutputStream out = new FileOutputStream(downloadDestination)) {
long start = 0;
long end = 1;
ContentRange contentRange;
do {
contentRange = downloadVideoBytes(managerTestId, out, start * 1024, end * 1024 - 1);
start++;
end++;
} while(contentRange.end < contentRange.total - 1);
}
}

class ContentRange {
Long start, end, total;
public ContentRange(String contentRange) {
String[] range = contentRange.split("[ -/]");
this.start = Long.valueOf(range[1]);
this.end = Long.valueOf(range[2]);
this.total = Long.valueOf(range[3]);
}
}
}