gpt4 book ai didi

html - 直接从链接下载图片

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

我想知道是否有办法为图片制作直接下载链接?当我做这样的事情时:

它会在浏览器或新标签页中打开图片。我希望当用户单击该链接时立即下载图像。有没有办法用 HTML/CSS 或 ASP.NET MVC 3 做到这一点?

我的页面有点像 tumblr 博客,主页上有几张图片,每张图片旁边都有“下载 HQ”按钮。

最佳答案

添加 HTTP header :

Content-Disposition: attachment; filename=<file name.ext> 

要在“另存为”对话框中显示的文件名在哪里(如 finances.xls 或 mortgage.pdf)- 不带 < 和 > 符号。

这是 MVC 框架中的一个示例:

public ActionResult Download()
{
var document = ...
var cd = new System.Net.Mime.ContentDisposition
{
// for example foo.bak
FileName = document.FileName,

// always prompt the user for downloading, set to true if you want
// the browser to try to show the file inline
Inline = false,
};
Response.AppendHeader("Content-Disposition", cd.ToString());
return File(document.Data, document.ContentType);
}

关于html - 直接从链接下载图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12230663/

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