简体   繁体   English

点击图片触发手机浏览器下载

[英]Click image to trigger download in mobile browser

I try to add a feature that allow user to click a thumbnail and download the original picture to their computer or mobile phone from their browser. 我尝试添加一项功能,允许用户单击缩略图并将原始图片从其浏览器下载到他们的计算机或手机中。

I have successfully done it at desktop browser with <a href="source" download></a> . 我已经通过<a href="source" download></a>在桌面浏览器上成功完成了此操作。

However, this doesn't work with mobile browser apps like ios Safari, etc. 但是,这不适用于ios Safari等移动浏览器应用程序。

Does anyone know how to implement this for mobile browser? 有谁知道如何为移动浏览器实现此功能?
Or is it available ? 还是可以使用?
I really need some help, thanks... 我真的需要一些帮助,谢谢...

Note: 注意:

The image is totally from front-end. 该图像完全来自前端。

The process is like: 流程类似于:
1. Someone upload the image 1.有人上传图片
2. Functions print image to canvas 2.功能打印图像到canvas
3. Adding text using canvas API context 3.使用canvas API上下文添加文本
4. Output to image source from canvas 4.从画布输出到图像源
5. Download the source ( Issue is in this step) 5.下载源(此步骤中的问题)

you should set name for atr download. 您应该为下载atr设置名称。

<a href="source" download="test.png"></a>

pay attention to source of image. 注意图片来源。 if you use image from sub domain or other domain, this will not work.i think that its for security and browsers in new update not allow direct download from other origin . 如果您使用来自子域或其他域的图像,则将无法使用。我认为,出于安全性考虑,新更新中的浏览器不允许直接从其他来源下载。 i also set allow origin to sub domain in header of site, but its not work. 我还设置允许起源到站点标头中的子域,但它不起作用。

so the solution is: use this tag in header of request of images. 所以解决方案是:在图像请求的标头中使用此标记。 it is a sample that i used in asp.net 这是我在asp.net中使用的示例

this.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + dname + extention + "\"");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM