2015-11-06 32 views
3

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

我有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 "[email protected]\*.doc;type=application/msword" 
"https://gateway.watsonplatform.net/document-conversion-experimental/api/v1/convert_document" 

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

回答

2

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

#!/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 "[email protected]$doc;type=application/pdf" "$URL" 
done 

文件转换documentationAPI Reference