Update Content-Disposition header to include 'attachment' for image responses

This commit is contained in:
Johnpaul 2025-07-17 23:50:43 +01:00
parent 650838fd6f
commit e844740bbf

View File

@ -465,7 +465,7 @@ class PromptServer():
buffer.seek(0) buffer.seek(0)
return web.Response(body=buffer.read(), content_type=f'image/{image_format}', return web.Response(body=buffer.read(), content_type=f'image/{image_format}',
headers={"Content-Disposition": f"filename=\"{filename}\""}) headers={"Content-Disposition": f"attachment; filename=\"{filename}\""})
if 'channel' not in request.rel_url.query: if 'channel' not in request.rel_url.query:
channel = 'rgba' channel = 'rgba'
@ -485,7 +485,7 @@ class PromptServer():
buffer.seek(0) buffer.seek(0)
return web.Response(body=buffer.read(), content_type='image/png', return web.Response(body=buffer.read(), content_type='image/png',
headers={"Content-Disposition": f"filename=\"{filename}\""}) headers={"Content-Disposition": f"attachment; filename=\"{filename}\""})
elif channel == 'a': elif channel == 'a':
with Image.open(file) as img: with Image.open(file) as img:
@ -502,7 +502,7 @@ class PromptServer():
alpha_buffer.seek(0) alpha_buffer.seek(0)
return web.Response(body=alpha_buffer.read(), content_type='image/png', return web.Response(body=alpha_buffer.read(), content_type='image/png',
headers={"Content-Disposition": f"filename=\"{filename}\""}) headers={"Content-Disposition": f"attachment; filename=\"{filename}\""})
else: else:
# Get content type from mimetype, defaulting to 'application/octet-stream' # Get content type from mimetype, defaulting to 'application/octet-stream'
content_type = mimetypes.guess_type(filename)[0] or 'application/octet-stream' content_type = mimetypes.guess_type(filename)[0] or 'application/octet-stream'
@ -514,7 +514,7 @@ class PromptServer():
return web.FileResponse( return web.FileResponse(
file, file,
headers={ headers={
"Content-Disposition": f"filename=\"{filename}\"", "Content-Disposition": f"attachment; filename=\"{filename}\"",
"Content-Type": content_type "Content-Type": content_type
} }
) )