gpt4 book ai didi

c# - 单击 ASHX 图片下载

转载 作者:太空宇宙 更新时间:2023-11-03 19:30:24 25 4
gpt4 key购买 nike

我正在使用 ashx 提供来自数据库的图像,是否可以让用户单击允许他们在计算机上下载文件的链接。 (IE 显示保存对话框)就像您下载文件一样。这可能吗?

最佳答案

如果您希望它提示保存,请确保在创建响应时添加以下行:

context.Response.AppendHeader("Content-Disposition",
"attachment;filename=" + filename);

这将使浏览器将其视为附件并通过保存对话框进行提示。

编辑:根据您的评论,确保您正确地构建了您的回复:

// set attachment header like above
// then you need to get your file in byte[] form
byte[] dataYouWantToServeUp = GetData();
// you can set content type as well
yourHttpContext.Response.ContentType = "image/jpg";
// serve up the response
yourHttpContext.Response.BinaryWrite(dataYouWantToServeUp);

关于c# - 单击 ASHX 图片下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5382950/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com