从 cloudinary url 下载图像

Him*_*yal 1 image download cloudinary reactjs

我有我的反应项目,我可以在其中编辑图像并生成新图像。现在我想下载生成的图像。我正在使用 cloudinary 来实现这一点,并且我有图像的 url。

但主要问题是我无法下载图像。我试过

<a href="link" download> Download </a>
Run Code Online (Sandbox Code Playgroud)

但这没有用。它只是打开图像但不下载它。

我只想下载图像,仅此而已。

如果您有任何想法请分享

实时沙箱https://codesandbox.io/s/interesting-mountain-lf4lk?file=/src/App.js

小智 9

您不需要外部库来实现该功能。只需添加 Cloudinary flags=>attachment转换(fl_attachment在 URL 中),这将设置Content-Disposition值为“attachment”的标头,然后文件就会下载。

<a href="https://res.cloudinary.com/demo/image/upload/fl_attachment/sample.jpg">Download</a>
Run Code Online (Sandbox Code Playgroud)

您可以选择使用格式设置下载文件的自定义文件名fl_attachment:my_custom_filename

<a href="https://res.cloudinary.com/demo/image/upload/fl_attachment:my_custom_filename/sample.jpg">Download</a>
Run Code Online (Sandbox Code Playgroud)