67 lines
1.9 KiB
Bash
Executable File
67 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Configuration
|
|
API_URL="http://localhost:8080"
|
|
CLIENT_ID="AAA" # The client ID is AAA
|
|
PDF_FILE="./test.pdf"
|
|
|
|
# Colors for output
|
|
GREEN='\033[0;32m'
|
|
RED='\033[0;31m'
|
|
NC='\033[0m' # No Color
|
|
|
|
echo "Document Upload Script"
|
|
echo "====================="
|
|
|
|
# Check if test.pdf exists
|
|
if [ ! -f "$PDF_FILE" ]; then
|
|
echo -e "${RED}Error: $PDF_FILE not found${NC}"
|
|
echo "Please create a test.pdf file first"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if API is running
|
|
echo "Checking if API is running..."
|
|
if ! curl -s -f "$API_URL/health" > /dev/null 2>&1; then
|
|
echo -e "${RED}Error: API is not running at $API_URL${NC}"
|
|
echo "Please start the API with: DISABLE_AUTH=true go run ./cmd/queryAPI"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}API is running${NC}"
|
|
|
|
# Verify client exists by trying to get its details
|
|
echo "Verifying client with ID '$CLIENT_ID' exists..."
|
|
CLIENT_CHECK=$(curl -s -o /dev/null -w "%{http_code}" "$API_URL/client/$CLIENT_ID")
|
|
|
|
if [ "$CLIENT_CHECK" != "200" ]; then
|
|
echo -e "${RED}Error: Client with ID '$CLIENT_ID' not found${NC}"
|
|
echo "Please ensure the client exists in the database"
|
|
exit 1
|
|
else
|
|
echo -e "${GREEN}Client '$CLIENT_ID' verified${NC}"
|
|
fi
|
|
|
|
# Upload document
|
|
echo "Uploading document..."
|
|
# Try different approaches based on what the server expects
|
|
# Using explicit content type for the file field
|
|
UPLOAD_RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "$API_URL/client/$CLIENT_ID/document" \
|
|
-F "file=@$PDF_FILE;type=application/octet-stream" \
|
|
-F "filename=test.pdf")
|
|
|
|
HTTP_CODE=$(echo "$UPLOAD_RESPONSE" | tail -n1)
|
|
RESPONSE_BODY=$(echo "$UPLOAD_RESPONSE" | sed '$d')
|
|
|
|
if [ "$HTTP_CODE" = "200" ]; then
|
|
echo -e "${GREEN}Document uploaded successfully!${NC}"
|
|
echo "Response: $RESPONSE_BODY"
|
|
else
|
|
echo -e "${RED}Error: Upload failed with HTTP $HTTP_CODE${NC}"
|
|
echo "Response: $RESPONSE_BODY"
|
|
exit 1
|
|
fi
|
|
|
|
echo ""
|
|
echo "You can check the uploaded documents with:"
|
|
echo "curl $API_URL/client/$CLIENT_ID/document" |