Endpoint
Authentication
This endpoint does not require authentication.Description
Proxy endpoint to fetch and serve PDF files from URLs, bypassing CORS restrictions for frontend preview functionality. This allows PDFs from external sources to be displayed in browser iframes without running into cross-origin issues.Request
Query Parameters
URL of the PDF to preview
- Must start with
http://orhttps:// - Examples: CloudFront URLs, S3 URLs, direct file links
- 60-second timeout, 50MB limit
Example Request
Response
Success Response (200 OK)
Content-Type:application/pdf
Headers:
Content-Disposition: inline; filename=preview.pdfX-Content-Type-Options: nosniff
Error Responses
400 Bad Request
Invalid URL format:Connection timeout- Server took too long to respond (>60s)File too large- PDF exceeds 50MB limitInvalid content type- URL does not point to a PDFHTTP 404- File not foundHTTP 403- Access denied
500 Internal Server Error
Example Usage
Using cURL
Using Browser (Direct Access)
Using HTML iframe
Using JavaScript (fetch)
Using React Component
Use Cases
1. Preview Before Processing
Allow users to preview PDFs from URLs before submitting them for tag generation:2. CORS Bypass for External PDFs
Many external PDF sources have CORS policies that prevent direct iframe embedding. This endpoint acts as a proxy to bypass those restrictions:3. Uniform Preview Experience
Provide a consistent preview experience for both uploaded files and URLs:Technical Details
How It Works
- Client requests preview with a PDF URL
- Backend validates URL format (http/https)
- Backend downloads PDF from URL (using
FileHandler.download_file()) - Backend validates downloaded content is a PDF
- Backend returns PDF with proper headers for inline display
Headers Explained
Content-Disposition: inline- Tells browser to display PDF inline (not download)
filename=preview.pdfprovides fallback name if user saves
- Prevents MIME type sniffing
- Ensures browser treats response as PDF
Limitations
- Maximum file size: 50MB
- Timeout: 60 seconds
- Rate limiting: Subject to backend rate limits
- URL requirements: Must be publicly accessible via HTTP/HTTPS
- No authentication: Cannot preview PDFs requiring auth headers
Security Considerations
This endpoint acts as an open proxy for PDF URLs. Consider implementing:- URL allowlist: Restrict to trusted domains
- Rate limiting: Prevent abuse
- Content validation: Verify downloaded content is actually a PDF
- Size limits: Prevent downloading huge files
- URL format validation (http/https only)
- File size limit (50MB)
- Timeout protection (60s)
- Content-Type validation
Source Code
Implementation:backend/app/routers/single.py:271
File Handler: backend/app/services/file_handler.py (download_file method)