Import document with bash script using REST
Simplified version of the script which make use of RESTful API.
#!/bin/bashOKM_SERVICE="http://localhost:8080/OpenKM"OKM_USER="okmAdmin"OKM_PASSWORD="admin"OKM_PATH="/okm:root/upload"LOCAL_PATH="."TMP=$(mktemp)RESET='\e[0m'ERROR='\e[1;31m'OK='\e[1;34m'
for DIR in $(find $LOCAL_PATH -type d); do DIR=${DIR:1:${#DIR}} if [ -n "$DIR" ]; then RETCODE=$(curl -u $OKM_USER:$OKM_PASSWORD --write-out %{http_code} -X POST --silent --output $TMP \ -H "Content-Type: application/json" -d "$OKM_PATH$DIR" "$OKM_SERVICE/services/rest/folder/createSimple") if [ $RETCODE != "200" ]; then echo -e "${ERROR}ERROR -> $(cat $TMP)${RESET}"; else echo -e "${OK}Folder created: ${OKM_PATH}${DIR}${RESET}" fi fidone
for FILE in $(find $LOCAL_PATH -type f); do FILE=${FILE:2:${#FILE}} RETCODE=$(curl -u $OKM_USER:$OKM_PASSWORD --write-out %{http_code} -X POST --silent --output $TMP \ -F "docPath=$OKM_PATH/$FILE" -F content=@$FILE "$OKM_SERVICE/services/rest/document/createSimple") if [ $RETCODE != "200" ]; then echo -e "${ERROR}ERROR -> $(cat $TMP)${RESET}"; else echo -e "${OK}Document created: ${OKM_PATH}/${FILE}${RESET}" fidone
# Cleanuprm -f $TMP