Visual Builder

Get Involved. Join the Conversation.

Topic

    Sudarshan Sharma
    upload file (content type - multipart/form-data )...
    Topic posted September 10, 2019 by Sudarshan SharmaRed Ribbon: 250+ Points 
    31 Views, 6 Comments
    Title:
    upload file (content type - multipart/form-data ) using picker using Content and Experience Cloud REST service
    Summary:
    upload file (content type - multipart/form-data ) using picker using Content and Experience Cloud REST service
    Content:

    Hi,

    I am trying to upload files to Oracle Content and Experience Cloud (CEC) service using REST Api. I am able to do this Using Postman APi and file got uploaded to oracle CEC.

    When trying the same from VBCS, i used file Picker component on UI. Since File Upload REST api for CEC is using below form parameters which i can pass in Postman inside Body section (Not  sure where to do this in Service Connection since body section got disabled after selecting Media type 'multipart/form-data' ) 

    Form Parameters

    Can you please guide here how to upload files to Content and Experience Cloud using Rest Api.

     

     

     

    Version:
    19.1.3

    Comment

     

    • David Konecny

      Here is what source JSON looks like for one of my action chains which uploads image to CEC. I think there is VB bug that when content type is multipart/form-data then body can't be mapped in the UI mapper and needs to be entered in the JSON source:

            "root": "callRestEndpoint1",
            "actions": {
              "callRestEndpoint1": {
                "module": "vb/action/builtin/restAction",
                "parameters": {
                  "endpoint": "documentsApi1_2/postFilesData",
                  "contentType": "multipart/form-data",
                  "body": {
                    "jsonInputParameters": "{{ '{ \"parentID\":\"' + $page.variables.folderId + '\"}' }}",
                    "primaryFile": "{{ $page.variables.uploadFile.files[0] }}"
                  },
                  "uriParams": {
                    "filename": "{{ 'NewFileNameHere.png' }}"
                  }
                },
                "outcomes": {
                  "success": "...",
                  "failure": "..."
                }
              },
      

      Let me know if that is not enough you need more details. The filename param is optional in case you want to rename uploaded file.

      -David

       

      • Sudarshan Sharma

        thanks David for your response. I was able to follow the above steps and stuck at below point..

        >  inside the body section did you define files variable of type upload file, if yes then i am not able to create a Type of rest endpoint because endpoint does not contain any fields.

        "primaryFile": "{{ $page.variables.uploadFile.files[0] }}"
        

        > also let me know while creating if you were able to test service connection based on CEC API.

        If possible can you please share screenshots from Action chain of your call Rest endpoint. 

    • David Konecny

      I defined

      "uploadFile": {
      "type": "object",
      "defaultValue": null
      }
       
      which gets populated via a value from <oj-file-picker>. And the variable is object which contains list of files and first one is the one I intend to upload, hence
      "primaryFile": "{{ $page.variables.uploadFile.files[0] }}"
      

      -David

       

      • Sudarshan Sharma

        Thanks David , i was able to upload file to CEC. Can you help with steps for how to get the response from the upload file Webservice and store FileId (which  should come as part of response)  in BO table. i have table created in my application with 2 attributes FileId and Filename .Once this service invocation is done , i should get the fileId from response and store in table.

        • David Konecny

          Which part of doing this is not clear? Do you know how to work with action chains in VB and how to access results of previous actions? To display uploaded file ID and its name I added eg fireNotificationEventAction:

                  "showResponse": {
                    "module": "vb/action/builtin/fireNotificationEventAction",
                    "parameters": {
                      "summary": "{{ \"ID=\" + $chain.results.takePhotoRenameCallRestEndpoint1.body.id + \n\" Name=\"+ $chain.results.takePhotoRenameCallRestEndpoint1.body.name }}"
                    },
                    "outcomes": {
                      "success": "callActionChain1"
                    }
                  }

          where "takePhotoRenameCallRestEndpoint1" is ID of action which uploads the image. And mapping of what to display I did in VB UI mapper where I can browse the response payload of the CEC POST action (see attached image).

          -David

           

          • Sudarshan Sharma

            David - thanks for your help. i was able to get file id and name from the response body. currently i am trying to parse these responses to the table so that when required we can pass file id from table and download to files from CEC. will update you if i stuck while parsing.

             

            Thank you so much for your quick responses!