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

不问归期 提交于 2020-01-11 09:58:05

问题


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:


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.



来源:https://stackoverflow.com/questions/33557966/how-to-convert-multiple-documents-using-the-document-conversion-service-ina-scri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!