python

fastapi에서 파일입출력을 할때 한글파일이름일때 처리방법

rkrkrr0101 2022. 12. 21. 02:11
 
#이거 그냥 복붙이니까 안쓰는건 알아서 빼시면됩니다
from fastapi import FastAPI, File, UploadFile, Response, status, Form, Request, APIRouter
from fastapi.responses import PlainTextResponse, StreamingResponse


@app.post("/path")#경로입력
def fun(file: UploadFile = File(...)):
    

    #파일처리
    ...
    #파일처리

    headers = {
        'Content-Disposition': "attachment; filename*=utf-8''{}.mp3".format(quote(Path(file.filename, encoding="UTF-8").stem+"_파일뒤추가문구"))} 

    return StreamingResponse(content=출력파일변수, headers=headers, media_type='audio/mp3')

이렇게 헤더에서 uft-8로 선언하고 던져줘야하고,StreamingResponse말고 몇개 시도해봤는데 다 잘 안돼서 저거로 했음