ibm-watsondocument-conversion

How to convert multiple documents using the Document Conversion service ina script bash?


How can I convert more than one document using the Document Conversion service.

I have between 50-100 MS Word and PDF documents that I want to convert using the convert_document API method?

For example, can you supply multiple .pdf or *.doc files like this?:

curl -u "username":"password" -X POST
-F "config={\"conversion_target\":\"ANSWER_UNITS\"};type=application/json" 
-F "file=@\*.doc;type=application/msword"
 "https://gateway.watsonplatform.net/document-conversion-experimental/api/v1/convert_document"

That gives an error unfortunately: curl: (26) couldn't open file "*.doc". I have also tried "file=@file1.doc,file2.doc,file3.doc" but that gives errors as well.


Solution

  • The service only accept one file at a time, but you can call it multiple time.

    #!/bin/bash
    USERNAME="<service-username>"
    PASSWORD="<service-password>"
    URL="https://gateway.watsonplatform.net/document-conversion-experimental/api/v1/convert_document"
    DIRECTORY="/path/to/documents"
    for doc in *.doc
    do
      echo "Converting - $doc"
      curl -u "$USERNAME:$PASSWORD" \
      -F 'config={"conversion_target":"ANSWER_UNITS"};type=application/json' \
      -F "file=@$doc;type=application/pdf" "$URL"
    done
    

    Document Conversion documentation and API Reference.