Upload

Uploads a file from the local machine to the repository. Files on the repository cannot be accessed directly. Use this command to upload data, metadata, and backup snapshots to a service instance. See About the EPM Automate Utility.

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.

This REST API is version 11.1.2.3.600.

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

Request

Supported Media Types: aapplication/octet-stream

Parameters:

The following table summarizes the client request.

Table 6-6 Parameters

Name Description Type Required Default
api_version Version of the API you are developing with Path Yes None

Response

Table 6-7 Parameters

Name Description Type Required Default
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.

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 Body

Supported Media Types: application/json

Table 6-8 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://<SERVICE_NAME>-<TENANT_NAME>.<SERVICE_TYPE>.<dcX>.oraclecloud.com/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 6-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";
	}

}