Skip to content

Instantly share code, notes, and snippets.

@pmedcraft
Last active April 16, 2019 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmedcraft/172303f695aae34d1422109ed11219d3 to your computer and use it in GitHub Desktop.
Save pmedcraft/172303f695aae34d1422109ed11219d3 to your computer and use it in GitHub Desktop.
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