How to POST a document in binary format?

Hello World,

I am looking for a way to make a Rest API call to post a document.

The document need to be converted in binary.

Best

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer
    The best thing I can suggest is to try out the File Upload smart service to see if it meets your needs: docs.appian.com/.../HTTP_File_Upload_Smart_Service.html
  • We are using base64 format to convert a document in to base64, but the converted value will not be in binary and still uses the binary format internally. Once we convert the document into base64 we are sending to External service there they will decode that and persist in their system.
  • 0
    Certified Lead Developer
    Hi as per my understanding File upload smart service is the best choice in your case.

    I will not recommended you to go for Base64 approach because of following reasons:

    1. Generally when we convert a document to Base64 then the output document size will be much bigger than the actual one

    2. When Base64 conversion happens, entire output Base64 data will be stored in memory instead of streaming it, which is why it's a memory intensive operation.

    3. If we are dealing with multiple and huge file operation, Base64 will impact the server performance a lot

    Solution: we should be able to stream the Document in Binary format, which can be done by using upload file smart service.

    Hope this will help
  • 0
    A Score Level 2
    in reply to aloks0189
    That's a good choice alok, but our requirement was to send only the document in base64, since the other service was used by many other applications. Hence we used that.
  • 0
    Certified Lead Developer
    in reply to chandu
    Agreed. If the requirement is pretty straight forward asking about Base64 format data only then it's obvious that we will be using send Bade64 document smart service, which you have implemented as well as per the requirement.
  • We are also converting the document to Base64 and trying to upload to SharePoint using Rest API call using Integration Object. The document is being created in the SharePoint but when we try to open the document(PDF), its crashing with an error message saying "Corrupted Data". Do you have any idea why this is happening.
  • 0
    Certified Lead Developer
    in reply to rameshg647

    Hi @rameshg647 this can happen in following cases:

    1. When conversion of the document to Base64 didn't happen properly

    2. While converting Base64 back to document in SharePoint: there might be something wrong they might have coded in SharePoint

    Alternate option: Why don't you give a try to http file upload smart service which is OOTB. This accepts headers , endpoint , basic authentication (if any) and the document. Here authentication can be done using integration object and the response header ( key and value) you can pass to this smart Service , that should do your job.

    And in fact, if Base64 is not only your requirement, then HTTP file upload smart service is the best option for you, because it stream the document in binary instead of converting and storing the entire document in memory (causes performance issues) which is being done by Base64 smart service.

    Hence If the target system is not expecting the document in Base64 format then I recommend you better go for http file upload smart Service.

    Hope this will help

  • PLease find my inline answers below:

    1. When conversion of the document to Base64 didn't happen properly: [The conversion was good, we were able to decode it back to appropriate file using online tools.]

    2. While converting Base64 back to document in SharePoint: there might be something wrong they might have coded in SharePoint[The conversion was good, we were able to decode it back to appropriate file using online tools.]

    Alternate option: Why don't you give a try to http file upload smart service which is OOTB. This accepts headers , endpoint , basic authentication (if any) and the document. Here authentication can be done using integration object and the response header ( key and value) you can pass to this smart Service , that should do your job.[We cannot use http file upload smart service as it only supports basic authentication.]

    And in fact, if Base64 is not only your requirement, then HTTP file upload smart service is the best option for you, because it stream the document in binary instead of converting and storing the entire document in memory (causes performance issues) which is being done by Base64 smart service.[We cannot use http file upload smart service as it only supports basic authentication. We can only use Integration object with Oauth authentication.]
    Please let us know if there is any thing we are missing.
  • 0
    Certified Lead Developer
    in reply to rameshg647

     You need to leave basic authentication input parameter empty, you just need to pass the headers, and in order to get the headers, authentication is required which will be done by Integration Object. Below are the steps to achieve this.

    1. Create an Integration Object which is responsible to perform the Authentication
    2. Call this integration Object in process model and get it's response, parse it
    3. Set the required headers Keys (let's say, OAuth, Cookie etc..) into HTTP File Upload Smart Service Headers Key and it's header values will be your parsed response (which you have got after authentication using Integration Object/or by any other authentication approach)
    4. set the endpoint of file upload

    And you are done, you will be able to upload the document to Sharepoint/any other system successfully.

    NOTE:
    1. HTTP File upload is a generic smart service which will work for most of the services, if we are able to provide the proper header details about the target system

    2. This is the reason, basic authentication input parameter is marked as not required in this Smart Service.

    Hope this will help.