Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 "[email protected],file2.doc,file3.doc" but that gives errors as well.

like image 750
German Attanasio Avatar asked Mar 16 '26 03:03

German Attanasio


1 Answers

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.

like image 99
German Attanasio Avatar answered Mar 20 '26 01:03

German Attanasio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!