Home > Software engineering >  How can I create download button for the file from third-party url?
How can I create download button for the file from third-party url?

Time:01-26

I have a music download button. As you can see, my music files are kept in aws s3 cloud.

<a href={`https://bucketname.s3.amazonaws.com/songs/name.mpeg`} download={"Name.mpeg"}>

In this case after clicking button I move to the new tab with the music file, and download is not triggered.

https://imgur.com/LYgET2k

What can I do if I want trigger download after clicking the button immediately?

P.S. I use NodeJS server

CodePudding user response:

Yeah you can do it like that

<a href="https://www.w3schools.com/images/myw3schoolsimage.jpg" download="filename">
  <img src="https://www.w3schools.com/images/myw3schoolsimage.jpg" alt="W3Schools" width="104" height="142">
</a>

CodePudding user response:

You should try assigning a _blank value to the <a> element's target attribute:

<a target="_blank" download={"Name.mpeg"} href={`https://bucketname.s3.amazonaws.com/songs/name.mpeg`}>
  Download Link
</a>

  •  Tags:  
  • Related