Download

Downloads a file from the repository to the current directory in the local environment.

If the content type of the response is application/JSON, then an error with details is displayed on the server. Otherwise, the content of the file is streamed through the response.

Note: The entire path to the file must be encoded, for example, changing / to %2F and spaces to %20. This API can be used to download files up to 1GB in a single request.

For example, change this path to an .HTML file in the apr directory:

apr/2020-03-04 23_07_20/2020-03-04 23_07_20.html

to this:

apr%2F2020-03-04%2023_07_20%2F2020-03-04%2023_07_20.html

This REST API is version 11.1.2.3.600.

Required Roles

Service Administrator

Power User assigned to the Migration Administrator Profitability and Cost Management application role

REST Resource

GET /interop/rest/{api_version}/applicationsnapshots/{applicationSnapshotName}/contents

Note:

Before using the REST resources, you must understand how to access the REST resources and other important concepts. See Implementation Best Practices for EPM Cloud REST APIs. Using this REST API requires prerequisites. See Prerequisites.

Request

The following table summarizes the GET request parameters.

Table 9-22 Parameters

Name Description Type Required Default
applicationSnapshotName

Application snapshot name or file name to download (for example, "Artifact Snapshot" or s112.csv).

The entire applicationSnapshotName must be encoded before sending the request.

To download a particular file, provide the path to that file as the value of applicationSnapshotName. For example, to download a Data Management file called s112.csv in the inbox, refer to the file as "inbox\s112.csv" in the path parameter.

To download the Activity Reports or access log, use the fully qualified file name as shown in the output of List Files.

For example, to download a specific file from the apr directory, use the following format: pr%2F2020-03-04%0A23_07_20%2F2020-03-04%0A23_07_20.html apr%2F%0A2020-03-04%2023_07_20%2F%0Aaccess_log.zip apr%2F%0A2020-03-04%2023_07_20%2F%0Aactivityreport.json.

Path Yes None
api_version Specific API version Path Yes None

Example of Request

https://<BASE-URL>/interop/rest/11.1.2.3.600/applicationsnapshots/Vision.zip/contents

Table 9-23 Parameters

Name Description
Details In case of errors, details are published with the error string
Status See Migration Status Codes
Links Detailed information about the link
Href Links to API call
Action The HTTP call type
Rel Possibly value: self
Data Parameters as key value pairs passed in the request

Response

Supported Media Types: application/json or application/octet-stream

Example of Response Body

The following shows an example of the response body in JSON format in case there is an error during download.

{
    "details": "Invalid file : Vision.zip",
    "status":1,
    "links":[{
		"href":"https://<BASE-URL>/interop/rest/11.1.2.3.600/applicationsnapshots/Vision.zip/contents",
		"action":"GET",
		"rel":"self",
		"data":null
    }]
}

Download Sample Code

Example 9-8 Java Sample – downloadFile.java

Prerequisites: json.jar

Common Functions: See Common Helper Functions for Java.

public class DownloadFile600 {

	private String serverUrl; // PBCS server URL
	private String apiVersion = "11.1.2.3.600";
	private String userName; // Server Username
	private String password; // Server Password
	private static String fileName; // file to be downloaded.

	public DownloadFile600(String userName, String password, String serverUrl, String apiVersion) {
		super();
		this.serverUrl = serverUrl;
		this.apiVersion = apiVersion;
		this.userName = userName;
		this.password = password;
	}

	public void downloadFile(String fileName) throws Exception {
		HttpURLConnection connection = null;
		InputStream inputStream = null;
		FileOutputStream outputStream = null;

		try {
			fileName = fileName.replaceAll("/", "\\\\");
			URL url = new URL(String.format("%s/interop/rest/%s/applicationsnapshots/%s/contents", serverUrl,
					apiVersion, URLEncoder.encode(fileName, "UTF-8")));

			System.out.println("DOWNLOAD URL: " + url);
			connection = (HttpURLConnection) url.openConnection();
			connection.setRequestMethod("GET");
			connection.setInstanceFollowRedirects(false);
			connection.setDoOutput(true);
			connection.setUseCaches(false);
			connection.setDoInput(true);
			connection.setRequestProperty("Authorization",
					"Basic " + new sun.misc.BASE64Encoder().encode((userName + ":" + password).getBytes()));
			int status = connection.getResponseCode();
			if (status == 200) {
				if (connection.getContentType() != null && connection.getContentType().equals("application/json")) {
					JSONObject json = new JSONObject(getStringFromInputStream(connection.getInputStream()));
					System.out.println("Error downloading file : " + json.getString("details"));
				} else {
					inputStream = connection.getInputStream();
					outputStream = downloadContent(connection, inputStream);
				}
			} else {
				throw new Exception("Http status code: " + status);
			}
		} finally {
			if (connection != null)
				connection.disconnect();
			if (outputStream != null)
				outputStream.close();
			if (inputStream != null)
				inputStream.close();
		}
	}

	private FileOutputStream downloadContent(HttpURLConnection connection, InputStream inputStream)
			throws FileNotFoundException, IOException {
		FileOutputStream outputStream;
		String downloadedFileName = fileName;
		if (fileName.lastIndexOf("/") != -1) {
			downloadedFileName = fileName.substring(fileName.lastIndexOf("/") + 1);
		}

		String ext = ".zip";
		if (connection.getHeaderField("fileExtension") != null) {
			ext = "." + connection.getHeaderField("fileExtension");
		}
		if (fileName.lastIndexOf(".") != -1 && fileName.lastIndexOf(".") != 0)
			ext = fileName.substring(fileName.lastIndexOf(".") + 1);

		outputStream = new FileOutputStream(new File(downloadedFileName + ext));
		int bytesRead = -1;
		byte[] buffer = new byte[5 * 1024 * 1024];
		while ((bytesRead = inputStream.read(buffer)) != -1)
			outputStream.write(buffer, 0, bytesRead);
		System.out.println("File download completed.");
		return outputStream;
	}

}