File size: 1,006 Bytes
57cf043
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import logging

from fastapi import APIRouter
from fastapi.responses import FileResponse

from components.services.files import FileService


router = APIRouter()

logger = logging.getLogger(__name__)

service = FileService()


@router.get("/download")
async def download_file(filename: str):
    file_path = service.prepare_file(filename)
    return FileResponse(
        file_path,
        filename=filename,
        media_type="application/xml",
        headers={
            "Content-Type": "application/xml; charset=cp866",
            "Access-Control-Expose-Headers": "Content-Disposition"
        }
    )
    
    
@router.get("/download_pdf")
async def download_pdf(filename: str):
    file_path = service.prepare_pdf(filename)
    return FileResponse(
        file_path,
        filename=f'{filename}.pdf',
        media_type="application/pdf",
        headers={
            "Content-Type": "application/pdf",
            "Access-Control-Expose-Headers": "Content-Disposition"
        }
    )