I am building an endpoint on my ExpressJS server to download an APK file given the correct credentials. Here is what my server endpoint looks like:
app.post('/App/download', (req, res) => {
//Check if password is correct
if(req.body.key == 'xxxxx') {
res.sendFile(path.join(__dirname, '..', '/server', '/AuthorizedClientResources', 'app.apk'), err => {
if(err)
console.log('Error is:\n', err)
})
} else {
//Any suggestions for invalid password handling would be appreciated
res.sendStatus(401)
}
})
And here is what my post request looks like on the client-side:
try {
axios.post('http://domainName/App/download', { key: this.appKey })
.then(response => {
console.log('Response was:\n', response)
})
.catch(err => (console.log('The error was:\n', err)))
} catch(error) {
alert(`You entered incorrect credentials.`)
}
When a response is received (given correct credentials) the file is sent and the response body looks like this using the Chrome developer tools. The file is 7.1MB on my file system and it is sent in the response as ~13MB.
Is there any reason for this?
Any help is appreciated. Thank you!