Force external download url

前端 未结 2 1259
天涯浪人
天涯浪人 2020-12-03 21:39

I want to host on my webpage an external url containing a mp3 file. The problem is that clicking on that link will open the player, i have to right click and \"Save link as\

2条回答
  •  清歌不尽
    2020-12-03 22:09

    EDIT: The answer below applies if you have control over the target MP3 file only, not if it is an external link

    The link should not go directly to the MP3 file, but to a piece of logic (are you using ASPX, for instance? In that case you can use an .aspx page as the target, or you can create an HTTP handler for the .mp3 extension) that adds an HTTP header to the output that contains the line:

    Content-Disposition: attachment;filename="whatever.mp3";
    

    This will instruct the browser to treat the contents of the output as a file to save locally.

提交回复
热议问题