如何在脚本 bash 中使用文档转换服务转换多个文档?

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

如何使用 Document Conversion 服务转换多个文档。

我有 50-100 个 MS Word 和 PDF 文档要使用 convert_document API 方法转换?

例如,您可以像这样提供多个 .pdf 或 *.doc 文件吗?:

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"

不幸的是,这给出了一个错误:curl: (26) 无法打开文件“*.doc”。 我也试过 "file=@file1.doc,file2.doc,file3.doc" 但这也会出错。

该服务一次只接受一个文件,但您可以多次调用它。

#!/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

文档转换documentation and API Reference.