Thank you Laurent.
I have created a automated task to upload the file to external API. I have achieved this using groovy script in external connector. This may not be the best implementation. But serves my purpose. Script below:
import org.bonitasoft.engine.api.DocumentAPI;
import org.bonitasoft.engine.api.ProcessRuntimeAPI;
import org.bonitasoft.engine.bpm.document.Document;
import org.bonitasoft.engine.bpm.document.DocumentNotFoundException;
import org.bonitasoft.engine.connector.ConnectorException;
ProcessRuntimeAPI processRuntimeAPI = apiAccessor.getProcessAPI();
String docName = templateDocument.getContentFileName();
String mimeType = templateDocument.getContentMimeType();
final byte[] contentByte = ((DocumentAPI) processRuntimeAPI).getDocumentContent(templateDocument.getContentStorageId());
//final ByteArrayInputStream templateDocumentByte = new ByteArrayInputStream(contentByte);
int templateDocumentByteLength = contentByte.length;
String query = String.format("category=%s&subCategory=%s&fileName=%s",
URLEncoder.encode(templateFile.getCategory(), "UTF-8"),
URLEncoder.encode(templateFile.getSubCategory(), "UTF-8"),
URLEncoder.encode(docName, "UTF-8"));
URL url = new URL(fileUploadUrl + "?" + query);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("POST");
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestProperty("Connection", "Keep-Alive");
conn.addRequestProperty("Content-length", templateDocumentByteLength.toString());
conn.addRequestProperty("file", mimeType);
OutputStream os = conn.getOutputStream();
os.write(contentByte)
os.close();
conn.connect();
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
println "File Uploaded!"
}
else{
throw new Exception("File Upload Failed!")
}