Best way to POST a file?

JEdward
JEdward New Altair Community Member
edited November 2024 in Community Q&A

Hi guys,

 

I want to take the binary data file of an image and upload via POST multipart/form-data to a webservice, then consume the (JSON) result.  

 

This should be possible with lots of writing in Groovy or Python, but is it possible in either the GetPage or EnrichData by WebService operators? 

 

 

Answers

  • Edin_Klapic
    Edin_Klapic New Altair Community Member

    Hi John,

     

    I am not 100% sure if I get you correct but this should work with the File Upload functionality described in this Knowledge base article. The upload functionality is not limited to MIME type Excel or CSV. 

    You could also use curl. For Enrich Data by Webservice the image needs to be in the body of the message.

     

    Hope this helps.

     

    Best,

    Edin

  • sgenzer
    sgenzer
    Altair Employee

    hi...I have tried to do something very similar with the Zamzar API where I am uploading a PDF binary.  I use cURL instead of Enrich Data via Webservice as the latter did not work well for me.  Here's my code - hopefully you will see what I was doing and adapt to your issue.

     

    <?xml version="1.0" encoding="UTF-8"?><process version="7.5.003">
    <context>
    <input/>
    <output/>
    <macros/>
    </context>
    <operator activated="true" class="process" compatibility="7.5.003" expanded="true" name="Process">
    <process expanded="true">
    <operator activated="true" class="productivity:execute_program" compatibility="7.5.003" expanded="true" height="103" name="Execute Program" width="90" x="45" y="34">
    <parameter key="command" value="sudo curl -u 11111: -X POST -F &quot;source_file=@/Users/GenzerConsulting/Desktop/foo.pdf&quot; -F &quot;target_format=html5&quot; https://sandbox.zamzar.com/v1/jobs"/>
    <parameter key="working_directory" value="/Users/GenzerConsulting/Desktop"/>
    <list key="env_variables"/>
    </operator>
    <operator activated="true" class="text:read_document" compatibility="7.5.000" expanded="true" height="68" name="Read Document" width="90" x="179" y="34"/>
    <operator activated="true" class="text:json_to_data" compatibility="7.5.000" expanded="true" height="82" name="JSON To Data" width="90" x="313" y="34"/>
    <connect from_op="Execute Program" from_port="out" to_op="Read Document" to_port="file"/>
    <connect from_op="Read Document" from_port="output" to_op="JSON To Data" to_port="documents 1"/>
    <connect from_op="JSON To Data" from_port="example set" to_port="result 1"/>
    <portSpacing port="source_input 1" spacing="0"/>
    <portSpacing port="sink_result 1" spacing="0"/>
    <portSpacing port="sink_result 2" spacing="0"/>
    </process>
    </operator>
    </process>

     

    Scott