Add document via REST with binary string

Options

Hello,

When using the REST API (POST /api/v1/nodes) to create a document int Content Server, can I pass in a binary string as the content of the file? Is there sample code for this? My page need to download a file from a web site (SharePoint) then upload it to Content Server without user intervention.

I know the API works for a File object of an “input” html control, as shown in the post: Create Document via REST. But in our scenario, we don't have a File Upload control on the page.

Thanks,
Matthew

Comments

  • Ferdinand Prantl
    Ferdinand Prantl E Community Moderator
    Options

    Technically, you can create a Blob object and append it to the FormData object as you do it with the File objects. The blob can be initialized by an ArrayBuffer, which you can receive by other AJAX call:

    var mimeType = ...,
        content = ...,
        blob = new Blob(content, {type : mimeType}),
        formData = new FormData();
    
    formData.append('file', blob);
    formData.append(...);
    
    $.ajax({
      url: '//server/otcs/cs/api/v1/nodes',
      type: 'POST',
      data: formData,
      processData: false,
      contentType: false
    });
    

    However, I should discourage you from this way of archiving files from SharePoint to Livelink. I see it usable for a prototype evaluating the REST API, but not suitable for a serious product. Downloading files to the local browser from the source server and uploading them to the target server then... Slower operation, wasted bandwith and tablet clients may not be able to perform the operation at all, if you need to copy/move dozens of MBs.

    You could consider deploying a low-trust provider-hosted app, which can be authorized using an Office 365 site. The app would perform the upload by talking server-to-server and you would trigger it from the source SharePoint Online site.