Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

File upload - Client & server

partlycloudySep 14 2016 — edited Sep 15 2016

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);

    }

});

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 13 2016
Added on Sep 14 2016
4 comments
1,128 views