Binary format data push to content server API (api/v1/nodes) OTCS version 24.3

Hi All ,

I am using web report rest client for getting the data downloaded from third party application.
Data is getting stored in below variable sample code:-

@method:GET
@secure:true
@header:[ll_reptag_!header /]
@output:JSON:binaryfile /]

My file is stored in variable names as binaryfile. My use case is i want to push this file to content server for which i have generated otcsticket using WR rest client and now i am calling the API.

https://servername/cs/cs/api/v1/nodes Post method

and i am setting the header with otcsticket. To create a document 4 params are required

parm 1) type =144

parm 2) name=filename

parm 3) parent_id=120871

parm 4) file=""

I cant upload the direct binary file in 4 parameter.

Any way to solve this issue ?

Thanks
Nitesh

Comments

  • appuq
    appuq Member
    edited February 3 #2

    Reach out to OT support. If they say Pay Professional Services, do that or look at how to do this with some custom coding. All you have to do is put the content as a File and use the File Upload method. I know you are trying to avoid that and be efficient but I haven't seen such examples

  • Thanks @appuq , but i found the solution using Blob

  • Well in that case you might consider posting the solution, the forum users could benefit.If it is not too much trouble

  • Glad to help community :-

    Use below AJAX code in your web report to get the data downloaded in your browser from binary to pdf format:-


    .then(response => {
    console.log("Response Status:", response); // Log HTTP status
    console.log("Response Headers:", response.headers); // Log headers
    if (!response.ok) {
    throw new Error(HTTP error! Status: ${response.status});}
    return response.blob();
    })
    .then(blob => {
    console.log("Blob Data:", blob); // Log the blob data
    let link = document.createElement("a");
    link.href = URL.createObjectURL(blob);
    link.download = "document.pdf"; // Adjust the file name if needed
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
    console.log(link);
    })
    .catch(error => console.error("Error downloading file:", error));
    </script>


    Thanks
    Nitesh