Ir al contenido
Otras versiones

Cargando…

Import document with bash script using REST

Esta página aún no está disponible en tu idioma.

Simplified version of the script which make use of RESTful API.

#!/bin/bash
OKM_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
fi
done
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}"
fi
done
# Cleanup
rm -f $TMP