Last active
April 16, 2019 15:40
-
-
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
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
public enum AssetLocationType { | |
SOURCE, | |
TARGET, | |
SOURCE_TARGET | |
} |
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
public enum AssetResourceType { | |
TASK, | |
PROJECT, | |
PROJECT_GROUP | |
} |
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
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