Anchor tag with download attribute opens file instead of downloading

后端 未结 2 588
醉话见心
醉话见心 2021-01-17 01:06

In my Reactjs application I used the anchor tag to download a txt file like below.

downloa         


        
2条回答
  •  萌比男神i
    2021-01-17 01:54

    Try like this

    import File from 'http://textfiles.com/......./sample.txt'; //Or the path could be any relative path to the local file.
    
    //Other code
    render() {
        return(
            //Code
            download
        )
    }
    

    But inorder to use like this, you should be confident that you will get the file without any issues. Better to download the file and access it from your own directory instead of calling from another server.

提交回复
热议问题