user11530349
user11530349

Reputation:

react js: install downloaded apk

I am playing around with reactjs and wanted to prompt an apk install, similar to how you would prompt a .zip download, I have:

return (
                    <div className="card border-0 flex-row flex-wrap p-0 m-0" style={{background:'none'}}>
                        <div className="col-2 p-0 m-0">
                            <div className="card-header border-0 m-0 mt-1 p-0">
                                <img className="imgBorder" src={require('./assets/img/car.jpg')} width={'95.6dp'} height={'119.5dp'} alt=""/>
                            </div>
                        </div>
                        <div className="col-10">
                            <div className="card-block align-items-center p-0 m-0">
                                <h4 className="card-title" style={{color:'white', fontWeight: 'bold'}}>{this.props.title}</h4>
                                <p className="card-text pl-5 mb-0" style={{color:'white', lineHeight:'1'}}>Sed ut perspiciatis unde omnis iste natus error sit...</p>
                                <p className="muted m-0 p-0" style={{color:'white', lineHeight:'1.4', fontSize:'80%'}}>05/05/20</p>
                                <a href={this.props.url} className="playBtn my-2"><SportsEsportsIcon /><Trans i18nKey='library.play'>Play</Trans> </a>
                            </div>
                        </div>
                        <div className="w-100"></div>
                    </div>
                );

and the href={this.props.url} is pointing to a server with a .apk file. However, when I install the app (PWA), instead of prompting for download, I get taken to the url where the file is. Anyway I can trigger the download?

Upvotes: 0

Views: 757

Answers (1)

Drew Reese
Drew Reese

Reputation: 203061

You need to specify the download attribute on the link, versus linking to the location alone.

Attributes

download

Prompts the user to save the linked URL instead of navigating to it. Can be used with or without a value

<a
  href={this.props.url}
  className="playBtn my-2"
  download
  // or download="myAwesomeApp.apk" if you wanted to provide a name hint
>
  <SportsEsportsIcon />
  <Trans i18nKey='library.play'>
    Play
  </Trans>
</a>

Upvotes: 1

Related Questions