APEX 5.0.3, Oracle 11.1
I POST to a REST API to upload a document user picks from the [File Browse] form input. The API expects multi-part form input with some metadata about the document and the document itself.
I use the following Javascript code in a dynamic action on a button click. This works fine.
Questions
1. How can I combine this with the regular APEX file upload action? In other words, I would like the same file to be uploaded to both locations (Oracle) as well as the REST API
2. How can I extract all the existing documents from an Oracle table and feed them to the REST API?
Thanks
var data = new FormData();
var body = {
"metadata": {
"id": "1234",
"name": "Name of document",
"date": "2016-09-14",
"categories": [{ "category1": "Value1", "category2": "Value2" }]
}
};
data.append('documentset',new Blob([JSON.stringify(body)],{type:"application/json"}));
data.append('document0', apex.jQuery('#P1_FILENAME')[0].files[0]);
apex.jQuery.ajax({
beforeSend: function(xhr){
xhr.withCredentials = true
},
url: 'http://server.com/v1/documents',
data: data,
cache: false,
contentType: false,
processData: false,
crossDomain: true,
type: 'POST',
success: function(d,status,xhr){
apex.jQuery("#upload-message").text("Document id is "+d.document.id);
}
});