Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Download a Task asset from SDL WorldServer using the REST API returning the path to the downloaded file
public enum AssetLocationType {
SOURCE,
TARGET,
SOURCE_TARGET
}
public enum AssetResourceType {
TASK,
PROJECT,
PROJECT_GROUP
}
public static String getAssetFromTask(String wsBaseUrl, String token, int taskId, String assetName,
String downloadLocation, AssetLocationType assetLocationType)
throws IOException, URISyntaxException {
File translatedFile = new File(downloadLocation, assetName);
URI getUri = new URIBuilder(wsBaseUrl + "/ws-api/v1/files/asset")
.addParameter("token", token)
.addParameter("resourceId", String.valueOf(taskId))
.addParameter("assetLocationType", assetLocationType.toString())
.addParameter("resourceType", AssetResourceType.TASK.toString())
.build();
HttpClient httpClient = HttpClientBuilder.create().build();
HttpGet httpGet = new HttpGet(getUri);
HttpResponse response = httpClient.execute(httpGet);
byte[] bytes = EntityUtils.toByteArray(response.getEntity());
FileUtils.writeByteArrayToFile(translatedFile, bytes);
return translatedFile.getPath();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment