如何从链接下载图像?

时间:2020-09-22 07:15:51

标签: html firebase vue.js download

当用户单击按钮时,我试图下载图像,但是当我单击按钮时,图像在浏览器中打开,而不是仅下载图像。链接是来自Firebase的图像。知道我做错了什么的人对我有解决方案吗?

<a href="https://firebasestorage.googleapis.com/v0/b/q-aviationdev.appspot.com/o/4%2F98906.jpg?alt=media&token=e19f9317-79c7-46d2-a758-40309b4c4f0f" download="Testiamge.jpg">
     <b-button size="sm"  @click="downloadImg(index)" class="mr-2">
      <font-awesome-icon :icon="['fas', 'download' ]" />
    </b-button>
    </a>

对不起,我的英语不好:)

1 个答案:

答案 0 :(得分:0)

为什么不简单地使用这一部分:

<a href="https://firebasestorage.googleapis.com/v0/b/q-aviationdev.appspot.com/o/4%2F98906.jpg?alt=media&token=e19f9317-79c7-46d2-a758-40309b4c4f0f" download="Testiamge.jpg">
    <img alt="ImageName" src="https://firebasestorage.googleapis.com/v0/b/q-aviationdev.appspot.com/o/4%2F98906.jpg?alt=media&token=e19f9317-79c7-46d2-a758-40309b4c4f0fe">
</a>

如果要使用按钮,可以尝试以下代码:

<a href="https://firebasestorage.googleapis.com/v0/b/q-aviationdev.appspot.com/o/4%2F98906.jpg?alt=media&token=e19f9317-79c7-46d2-a758-40309b4c4f0f" download> 
    <button>Download image</button> 
</a> 

如果您使用的是IE,请尝试以下一种方法:

<a href="https://firebasestorage.googleapis.com/v0/b/q-aviationdev.appspot.com/o/4%2F98906.jpg?alt=media&token=e19f9317-79c7-46d2-a758-40309b4c4f0f" download target="_blank">Download image</a>