简体   繁体   English

在 IOS (Iphone/Ipad) 移动浏览器上自动下载存储在 S3 中的图像

[英]Auto-download an image stored in S3 on IOS (Iphone/Ipad) mobile browser

Hope you guys are doing fine.希望你们一切都好。

We are developing a functionality where customers can click on the download button and download an image.我们正在开发一种功能,客户可以单击下载按钮并下载图像。 Image is stored in S3 and a public URL is generated which is kept behind the button.图像存储在 S3 中,并生成一个公共的 URL,它保留在按钮后面。

Something like就像是

<a href="S3Url">Download</a>

Current exp: When customer clicks on the download button Current exp:当客户点击下载按钮时

  • For desktop - windows / IOS (Mac) - auto download is happening对于桌面 - windows / IOS (Mac) - 正在自动下载
  • When we are trying on android mobile browser - auto-download is happening当我们在 android 移动浏览器上尝试时 - 自动下载正在发生
  • When we are trying on IOS mobile browser (iPhone/Ipad), the file is just opening, no auto-download.当我们在 IOS 移动浏览器(iPhone/Ipad)上尝试时,文件只是打开,没有自动下载。
  • When we are trying on the mobile browser using a chrome toggle device on MAC(which technically acts as a mobile browser) - auto-download is happening.当我们在 MAC 上使用 chrome 切换设备(技术上充当移动浏览器)尝试移动浏览器时 - 自动下载正在发生。

So need assistance on所以需要帮助

  • Whether it's possible to auto-download the image in iPhone/Ipad browser using the S3 public link?是否可以使用 S3 公共链接在 iPhone/Ipad 浏览器中自动下载图像? If yes how can we achieve it?如果是,我们如何实现它?

Note:笔记:

  • Code written is in JavaScript to trigger the download.编写的代码在 JavaScript 中以触发下载。
Sample:
var downloadElement = document.createElement('a');
downloadElement.href = S3Url;
downloadElement.click();
  • Browsers tried are chrome, firefox, and safari.尝试的浏览器是 chrome、firefox 和 safari。 Experience is the same across browsers.跨浏览器的体验是相同的。

You can try adding the download attribute to your links.您可以尝试将download属性添加到您的链接。 This allows it work correctly for me using Safari.这允许它在我使用 Safari 时正常工作。

Something like this, perhaps:像这样的东西,也许:

var downloadElement = document.createElement('a');
downloadElement.href = S3Url;
downloadElement.download = "filename.jpg";
downloadElement.click();

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-download https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-download

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

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