How to convert multiple documents using the Docume

2020-04-10 03:19发布

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.

1条回答
你好瞎i
2楼-- · 2020-04-10 03:43

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.

查看更多
登录 后发表回答