Improve generated file's filename
This commit is contained in:
parent
8f841fe3a3
commit
7bb8fb0287
13
app/app.py
13
app/app.py
@ -85,13 +85,24 @@ async def generate_rest(name: str):
|
|||||||
break
|
break
|
||||||
bytes_io.write(data)
|
bytes_io.write(data)
|
||||||
|
|
||||||
|
out_filename = secure_filename(name)
|
||||||
|
|
||||||
|
# a tester found that, if only special characters (like _) are sent to this method, it will return an
|
||||||
|
# empty string
|
||||||
|
# to improve UX, we replace empty strings with a _
|
||||||
|
if not out_filename:
|
||||||
|
out_filename = "_"
|
||||||
|
|
||||||
|
# to further improve the UX, let's add some prefix and the .stl suffix
|
||||||
|
out_filename = f"bottle-clip-{out_filename}.stl"
|
||||||
|
|
||||||
# using secure_filename allows us to send the file to the user with some safe yet reasonably
|
# using secure_filename allows us to send the file to the user with some safe yet reasonably
|
||||||
# identifiable filename
|
# identifiable filename
|
||||||
return await send_file(
|
return await send_file(
|
||||||
bytes_io,
|
bytes_io,
|
||||||
mimetype="model/stl",
|
mimetype="model/stl",
|
||||||
as_attachment=True,
|
as_attachment=True,
|
||||||
attachment_filename=secure_filename(f"{name}.stl")
|
attachment_filename=out_filename,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user