如何在脚本bash中使用文档转换服务转换多个文档? [英] How to convert multiple documents using the Document Conversion service ina script bash?
本文介绍了如何在脚本bash中使用文档转换服务转换多个文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用文档转换服务.
我有50-100个要使用 convert_document
API方法?
I have between 50-100 MS Word and PDF documents that I want to convert using the convert_document
API method?
例如,您可以提供多个.pdf或* .doc这样的文件吗?:
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"
不幸的是,这将导致错误:curl:(26)无法打开文件"* .doc". 我也尝试过"file = @ file1.doc,file2.doc,file3.doc",但这也会产生错误.
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.
推荐答案
该服务一次仅接受一个文件,但您可以多次调用它.
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
这篇关于如何在脚本bash中使用文档转换服务转换多个文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文