Force download instead of streaming of mp3 file in FF

后端 未结 4 1127
滥情空心
滥情空心 2021-01-02 07:54

As the title says, I\'d like to download a mp3-file instead of playing it in Firefox.

I do it like this:



        
相关标签:
4条回答
  • 2021-01-02 08:10

    Write this

    <a href="http://test.com/path/to/my/file.mp3" download></html> WRONG

    should be

    <a href="http://test.com/path/to/my/file.mp3" download="file.mp3">download</a>
    
    0 讨论(0)
  • 2021-01-02 08:11

    Tested 8/18, Firefox correctly handles a simple download attribute. The accepted and second-ranked answers are wrong, at least as of now.

    So, simply,

    <a href="http://test.com/path/to/my/file.mp3" download></a>
    

    will work, and if you want to control what the file is downloaded as, you give download a value:

    <a href="http://test.com/path/to/my/file.mp3" download="use-this-name.mp3"></a>
    

    That is why Chrome (or any modern browser) will download it as "true.mp3" if you try to use download="true" instead of a simple download to force the file download.



    Also, note that <a></html> in the question isn't valid, and could have possibly caused a problem at the time if that's not just a typo.

    0 讨论(0)
  • 2021-01-02 08:17

    I used <a href="http://test.com/path/to/my/file.mp3" download >download</a> If you use the download="true" inside the anchor This will result in the renaming of the file name to true.mp3 in chrome an firefox as mention above.

    0 讨论(0)
  • 2021-01-02 08:22

    This is the correct way to force the download:

    <a href="http://test.com/path/to/my/file.mp3" download="true">download</a>
    

    NB: it will work on Firefox only if the file is located on the same domain unfortunately, cf. https://bugzilla.mozilla.org/show_bug.cgi?id=874009

    0 讨论(0)
提交回复
热议问题