Skip to content

Commit

Permalink
Merge pull request #34 from kang2453/master
Browse files Browse the repository at this point in the history
feat: improve filename handling in file download response
  • Loading branch information
kang2453 authored Jan 7, 2025
2 parents ac520aa + eefe03a commit 353f22c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/spaceone/file_manager/interface/rest/file.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging


from urllib.parse import quote
from typing import Optional
from fastapi import Request, Depends, File, UploadFile
from fastapi.responses import StreamingResponse
Expand Down Expand Up @@ -189,8 +190,15 @@ async def download_file(self, metadata, params) -> StreamingResponse:
except Exception as e:
raise ERROR_FILE_DOWNLOAD_FAILED(name=file_info["name"])


filename = quote(file_info['name'])
headers = {
"Content-Disposition": f"attachment; filename*=UTF-8''{filename}",
"content-length": str(obj['ContentLength']),
}

return StreamingResponse(
content=obj["Body"],
media_type="application/octet-stream",
headers={"Content-Disposition": f"attachment; filename={file_info['name']}", "content-length": str(obj["ContentLength"])}
headers=headers,
)

0 comments on commit 353f22c

Please sign in to comment.