File size: 2,559 Bytes
09281fe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python3
"""
Test Upload Endpoint
This script tests the file upload functionality
"""

import requests
import os

# Your ngrok URL
BASE_URL = "https://0468c638cef7.ngrok-free.app"

def test_upload():
    """Test file upload"""
    print("πŸ§ͺ Testing File Upload...")
    
    # Check if we have a test file
    test_files = ["doc2.pdf", "main.py", "app.py"]
    test_file = None
    
    for file in test_files:
        if os.path.exists(file):
            test_file = file
            break
    
    if not test_file:
        print("❌ No test file found. Please ensure you have a PDF file in the directory.")
        return False
    
    print(f"πŸ“ Using test file: {test_file}")
    
    url = f"{BASE_URL}/hackrx/upload"
    
    try:
        with open(test_file, 'rb') as f:
            files = {'file': (test_file, f, 'application/pdf')}
            print(f"⏳ Uploading {test_file}...")
            response = requests.post(url, files=files, timeout=60)
        
        print(f"Status: {response.status_code}")
        if response.status_code == 200:
            print("βœ… Upload successful!")
            result = response.json()
            print(f"Response: {result}")
            return True
        else:
            print(f"❌ Upload failed: {response.text}")
            return False
            
    except Exception as e:
        print(f"❌ Error: {e}")
        return False

def test_health_first():
    """Test health endpoint first"""
    print("πŸ§ͺ Testing Health Endpoint...")
    try:
        response = requests.get(f"{BASE_URL}/api/health", timeout=10)
        if response.status_code == 200:
            print("βœ… Health check passed!")
            return True
        else:
            print(f"❌ Health check failed: {response.text}")
            return False
    except Exception as e:
        print(f"❌ Error: {e}")
        return False

def main():
    """Run upload test"""
    print("πŸš€ Upload Test")
    print("=" * 40)
    
    # Test health first
    if not test_health_first():
        print("\n❌ Server not responding. Make sure Flask server is running!")
        print("Run: python app.py")
        return
    
    # Test upload
    test_upload()
    
    print("\n" + "=" * 40)
    print("πŸ“‹ POSTMAN UPLOAD GUIDE")
    print("=" * 40)
    print("1. Method: POST")
    print(f"2. URL: {BASE_URL}/hackrx/upload")
    print("3. Body: form-data")
    print("4. Key: file (Type: File)")
    print("5. Value: Select your PDF file")
    print("=" * 40)

if __name__ == "__main__":
    main()