File size: 824 Bytes
df6525b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI, HTTPException,Query
import json

app = FastAPI()

@app.post("/process-document-base64")
async def process_document_base64(request_data: dict):
    # If receiving base64 string directly
    payload = {
        "skipHumanReview": True,
        "rawDocument": {
            "mimeType": "application/pdf",
            "content": request_data['base64_content']
        }
    }
    
    access_token = get_access_token()
    
    headers = {
        'Authorization': f'Bearer {access_token}',
        'Content-Type': 'application/json; charset=utf-8'
    }
    
    response = requests.post(
        'https://us-documentai.googleapis.com/v1/projects/YOUR_PROJECT_ID/locations/us/processors/YOUR_PROCESSOR_ID:process',
        headers=headers,
        json=payload
    )
    
    return response.json()