curl --request POST \
--url https://api.example.com/api/batch/validate-paths \
--header 'Content-Type: application/json' \
--data '
{
"paths": [
{
"path": "<string>",
"type": "<string>"
}
]
}
'{
"results": [
{
"path": "<string>",
"valid": true,
"error": "<string>",
"content_type": "<string>",
"size": 123
}
],
"total": 123,
"valid_count": 123,
"invalid_count": 123
}Pre-flight validation of file paths before batch processing
curl --request POST \
--url https://api.example.com/api/batch/validate-paths \
--header 'Content-Type: application/json' \
--data '
{
"paths": [
{
"path": "<string>",
"type": "<string>"
}
]
}
'{
"results": [
{
"path": "<string>",
"valid": true,
"error": "<string>",
"content_type": "<string>",
"size": 123
}
],
"total": 123,
"valid_count": 123,
"invalid_count": 123
}Authorization: Bearer your_access_token
{
"paths": [
{
"path": "https://example.com/document.pdf",
"type": "url"
},
{
"path": "s3://my-bucket/documents/report.pdf",
"type": "s3"
},
{
"path": "/absolute/path/to/file.pdf",
"type": "local"
}
]
}
{
"results": [
{
"path": "https://example.com/document.pdf",
"valid": true,
"error": null,
"content_type": "application/pdf",
"size": 1024000
},
{
"path": "s3://my-bucket/missing.pdf",
"valid": false,
"error": "Object not found",
"content_type": null,
"size": null
},
{
"path": "/absolute/path/to/file.pdf",
"valid": true,
"error": null,
"content_type": null,
"size": 2048000
}
],
"total": 3,
"valid_count": 2,
"invalid_count": 1
}
type: "url":
http:// or https://)Content-Type and Content-Length headers"URL must start with http:// or https://" - Invalid URL format"HTTP 404" - File not found"HTTP 403" - Access forbidden"Request timed out" - Server didn’t respond in time"Request failed: [details]" - Network or connection errortype: "s3":
s3://bucket/key and bucket/key formatshttp, validates as URL insteadhead_object() to check existenceContentType and ContentLength from response"S3 client not configured" - AWS credentials not set up"Invalid S3 path format" - Missing key component"Object not found" - S3 key doesn’t exist"Bucket not found" - S3 bucket doesn’t exist"S3 error: [details]" - Permission or network errortype: "local":
"File not found: [path]" - Path doesn’t exist"Not a file" - Path points to a directory"Relative paths not supported" - Must use absolute path"Path validation error: [details]" - Permission or OS error{
"path": "",
"valid": false,
"error": "Empty path",
"content_type": null,
"size": null
}
{
"path": "ftp://example.com/file.pdf",
"valid": false,
"error": "Unknown path type: ftp",
"content_type": null,
"size": null
}
curl -X POST "http://localhost:8000/api/batch/validate-paths" \
-H "Authorization: Bearer your_access_token" \
-H "Content-Type: application/json" \
-d '{
"paths": [
{
"path": "https://example.com/doc1.pdf",
"type": "url"
},
{
"path": "https://example.com/doc2.pdf",
"type": "url"
}
]
}'
interface ValidationRequest {
paths: Array<{
path: string;
type: 'url' | 's3' | 'local';
}>;
}
interface ValidationResult {
path: string;
valid: boolean;
error: string | null;
content_type: string | null;
size: number | null;
}
interface ValidationResponse {
results: ValidationResult[];
total: number;
valid_count: number;
invalid_count: number;
}
async function validatePaths(
paths: Array<{ path: string; type: 'url' | 's3' | 'local' }>,
token: string
): Promise<ValidationResponse> {
const response = await fetch('http://localhost:8000/api/batch/validate-paths', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ paths }),
});
if (!response.ok) {
throw new Error(`Validation failed: ${response.statusText}`);
}
return response.json();
}
// Usage
const results = await validatePaths(
[
{ path: 'https://example.com/doc.pdf', type: 'url' },
{ path: 's3://my-bucket/doc.pdf', type: 's3' },
],
'your_access_token'
);
console.log(`Validated ${results.total} paths`);
console.log(`Valid: ${results.valid_count}, Invalid: ${results.invalid_count}`);
results.results.forEach(result => {
if (!result.valid) {
console.error(`Invalid: ${result.path} - ${result.error}`);
}
});
import requests
from typing import List, Dict, Literal
def validate_paths(
paths: List[Dict[str, str]],
token: str,
base_url: str = "http://localhost:8000"
) -> Dict:
response = requests.post(
f"{base_url}/api/batch/validate-paths",
headers={
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
},
json={"paths": paths}
)
response.raise_for_status()
return response.json()
# Usage
paths = [
{"path": "https://example.com/doc1.pdf", "type": "url"},
{"path": "s3://bucket/doc2.pdf", "type": "s3"},
{"path": "/tmp/doc3.pdf", "type": "local"},
]
result = validate_paths(paths, "your_access_token")
print(f"Valid: {result['valid_count']}/{result['total']}")
for validation in result['results']:
if not validation['valid']:
print(f"Error: {validation['path']} - {validation['error']}")
else:
print(f"OK: {validation['path']} ({validation['size']} bytes)")