Upload

Uploads a file from the current directory on the local machine to the repository. Files on the repository cannot be accessed directly.

If a file already exists, the API gives an error and does not overwrite it. Use this command to upload data, metadata, and back up snapshots to a service instance. See About EPM Automate in Working with EPM Automate for Oracle Enterprise Performance Management Cloud.

If a -1 status is returned and it is the last chunk to be uploaded, this means that an LCM artifact snapshot has been uploaded and zip extraction is in progress. The client pings the URL until the status is a positive integer. This job is done asynchronously.

Note: The entire path to the file must be encoded, for example, changing / to %2F and spaces to %20.

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

POST /interop/rest/11.1.2.3.600/applicationsnapshots/{applicationSnapshotName}/contents

Note:

For Data Management uploads, use the following JSON format for the query parameter:

/interop/rest/11.1.2.3.600/applicationsnapshots/{applicationSnapshotName}/contents?extDirPath=inbox

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

Supported Media Types: application/octet-stream

The following table summarizes the client request.

Table 9-20 Parameters

Name Description Type Required Default
api_version Version of the API you are developing with Path Yes None
applicationSnapshotName Name of the application snapshot or file name to be uploaded (for example, "Artifact Snapshot.zip" or s112.csv). A file with this name is created in the repository. If a file or folder with this name exists in the repository, an error indicates that a file or folder exists Path Yes None
extDirPath

Used to support upload of Data Management files.

Supported values include:

  • inbox - Upload files into the inbox; except for Profitability and Cost Management, Oracle Enterprise Performance Management Cloud business processes look in this location for files to process
  • profitinbox - Upload files to be processed by Profitability and Cost Management
  • to_be_imported - Upload a Narrative Reporting snapshot that is to be imported during the next daily maintenance of the environment
  • outbox - Upload files to the outbox for all EPM Cloud business processes except for Profitability and Cost Management
  • profitoutbox - Upload files to the outbox for Profitability and Cost Management

You can also use a directory under inbox, outbox, profitinbox, and profitoutbox, for example, inbox/directory_name

Example: "extDirPath= inbox/directory_name" to upload files to a directory within the inbox for processing by Data Management.

Upload: /interop/rest/11.1.2.3.600/applicationsnapshots/applicationSnapshotName/contents?extDirPath=inbox%2Fdm_folder

Example: "extDirPath=inbox" where inbox is the folder where the Data Management file is to be uploaded

Example of query parameters in JSON format for Data Management Upload: /interop/rest/11.1.2.3.600/applicationsnapshots/{applicationSnapshotName}/contents?extDirPath=inbox

Query No None

Response

Supported Media Types: application/json

Table 9-21 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 Possible values: self, recreate service
data Parameters as key value pairs passed in the request

Example of Response Body

The following shows an example of the response body in JSON format.

{
	"status":0,
	"details":null,
	"links":[{
		"data":null,
		"action":"POST",
	"href":"https://<BASE-URL>/interop/rest/11.1.2.3.600/applicationsnapshots/{applicationSnapshotName}/contents

REST API Examples with Postman

See REST API Examples with Postman.

Upload Sample Code

Example 9-7 Java Sample – 11.1.2.3.600

Prerequisites: json.jar

/**
 * 
 * Simple Implementation class to execute Upload functionality for API version 11.1.2.3.600
 */
public class UploadFile
{

	private final static String userName ; // User name
	private final static String password ; // Password
	private final static String serverUrl; // Server URL
	private String filePath ; //zip File to be Uploaded
	private String extDirPath = "inbox"; // keep it null for uploading to root directory
	private String details = null;
	
    public void uploadFile() {		
		
		boolean status = true;		

		try {			
			status = sendFileContents(filePath, extDirPath);			
			
			if(status)
				System.out.println("Uploaded contents to " + new File(filePath).getName());
			else
				System.err.println(details);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	

	private boolean sendFileContents(String filePath, String extDirPath)
			throws Exception {
		HttpURLConnection connection = null;
		FileInputStream content = null;
		File file = new File(filePath);
		
		try {
			String restURL = String.format(
					"%s/interop/rest/11.1.2.3.600/applicationsnapshots/%s/contents",
					serverUrl, URLEncoder.encode(file.getName(), "UTF-8"));
			if(null != extDirPath)
				restURL = restURL + "?extDirPath="+extDirPath;
			URL url = new URL(restURL);
			connection = (HttpURLConnection) url.openConnection();
			connection.setRequestMethod("POST");
			connection.setInstanceFollowRedirects(false);
			connection.setDoOutput(true);
			connection.setUseCaches(false);
			connection.setDoInput(true);
			
			String creds = null;
			
			
			creds = userName + ":" + password;
			
			connection.setRequestProperty("Authorization",
					"Basic " + new sun.misc.BASE64Encoder().encode(creds.getBytes()));
			connection.setRequestProperty("Content-Type", "application/octet-stream");
			
			content = new FileInputStream(file);
			OutputStream paramOutputStream = connection.getOutputStream();
			if (content != null) {
	            byte[] arrayOfByte = new byte[4096];	            
	            boolean hasMore = true;
	            while (hasMore) {
	                int j = content.read(arrayOfByte);
	                if (j < 0) {
	                	hasMore = false;
	                	continue;
	                }
	                paramOutputStream.write(arrayOfByte, 0, j);	             
	            }
	        }		
			
			int statusCode = connection.getResponseCode();
			
			String responseBody = getStringFromInputStream(connection.getInputStream());
			if (statusCode == 200 && responseBody != null) {
				int commandStatus = getCommandStatus(responseBody);
				if (commandStatus == -1) {
					getJobStatus(fetchPingUrlFromResponse(responseBody, "Job Status"), "GET");
				}
				if (commandStatus == 0) {					
					return true;
				}
				else{
					details = getDetails(responseBody);
				}
			}			

			return false;
		} finally {
			if(null != content)
				content.close();
			if (connection != null)
				connection.disconnect();
		}
	}



  
/**
 * Method to retrieve the error message
 * @param response
 * @return String details
 * @throws Exception
 */
	private String getDetails(String response) throws Exception {
		JSONObject json = new JSONObject(response);
		if (!JSONObject.NULL.equals(json.get("details")))
			return json.getString("details");
		else
			return "NA";
	}

}
Common Functions