99
1010# Check that a workspace exists
1111workspace_id=$( cat config/WORKSPACE_ID)
12+ workspace_name=$( cat config/WORKSPACE_NAME)
1213if [ -z " $workspace_id " ]; then
1314 echo " Please create a workspace before running this example"
1415 exit 0
@@ -35,34 +36,65 @@ declare -a Headers=(
3536)
3637# ds-snippet-end:Workspaces2Step2
3738
39+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
40+ DEMO_DOCS_PATH_UNIX=" $( cd " $SCRIPT_DIR /../../demo_documents" && pwd) "
41+
42+ if command -v cygpath > /dev/null 2>&1 ; then
43+ DEMO_DOCS_PATH=" $( cygpath -w " $DEMO_DOCS_PATH_UNIX " ) "
44+ else
45+ DEMO_DOCS_PATH=" $DEMO_DOCS_PATH_UNIX "
46+ fi
3847
3948# Upload the file path to be added to the workspace
4049# ds-snippet-start:Workspaces2Step3
41- echo " "
42- echo " Enter the path to the document you want to add to the workspace:"
43- echo " "
44- read file_path
50+ while true ; do
51+ echo " "
52+ echo " Enter the PDF file name (e.g. World_Wide_Corp_Web_Form.pdf) from the ${DEMO_DOCS_PATH} folder:"
53+ echo " "
54+ read file_name
4555
46- if [ ! -f " $file_path " ]; then
47- echo " File does not exist: $file_path "
48- exit 1
49- fi
56+ file_path=" $DEMO_DOCS_PATH /$file_name "
57+
58+ if [[ " $file_name " != * .pdf ]]; then
59+ echo " "
60+ echo " The file must be a PDF (must end with .pdf). Please try again."
61+ continue
62+ fi
63+
64+ if [ ! -f " $file_path " ]; then
65+ echo " "
66+ echo " File not found in demo_documents folder."
67+ continue
68+ fi
69+ break
70+ done
5071
5172# Enter the document name for the workspace
5273echo " "
53- echo " Enter the name for the document in the workspace:"
74+ echo " Enter the name for the document in the workspace (must end with .pdf) :"
5475echo " "
5576
56- read doc_name
77+ while true ; do
78+ read doc_name
79+
80+ doc_name=$( echo " $doc_name " | xargs)
81+
82+ if [[ " $doc_name " =~ \. pdf$ ]]; then
83+ break
84+ else
85+ echo " "
86+ echo " Invalid name. The document name must end with '.pdf' (e.g., example.pdf)."
87+ echo " Please try again:"
88+ fi
89+ done
5790# ds-snippet-end:Workspaces2Step3
5891
5992# apx-snippet-start:addWorkspaceDocument
6093# ds-snippet-start:Workspaces2Step4
6194Status=$( curl -s -w " %{http_code}" -o " ${response} " \
6295 --request POST " ${base_path} /accounts/${account_id} /workspaces/${workspace_id} /documents" \
6396 " ${Headers[@]} " \
64- -F " file=@${file_path} " \
65- -F " name=${doc_name} "
97+ -F " file=@${file_path} ;filename=${doc_name} " \
6698)
6799# ds-snippet-end:Workspaces2Step4
68100# apx-snippet-end:addWorkspaceDocument
@@ -84,7 +116,8 @@ echo ""
84116
85117# Pull out the document ID and save it
86118document_id=$( cat $response | grep document_id | sed ' s/.*"document_id":"//' | sed ' s/".*//' )
87- echo " Document added! ID: ${document_id} "
119+ echo " "
120+ echo " Document added to the workspace '${workspace_name} '! ID: ${document_id} "
88121echo ${document_id} > config/DOCUMENT_ID
89122
90123rm " $response "
0 commit comments