node.js: serve a file (apk in particular) upon successful authentication on a get request

前端 未结 1 1623
粉色の甜心
粉色の甜心 2021-01-24 09:39

Alright, I am trying to serve an apk file using node.js upon successful authentication of a get request. For this purpose I am using an api call of the form:

GET         


        
相关标签:
1条回答
  • 2021-01-24 10:07

    Express has a function to download files

    var apkFile = THE_ACTUAL_PATH_TO_THE_APK_NOT_UNDER_PUBLIC
    if(!fs.existsSync(apkFile))
        return res.status(404).send('Sorry no APKs here');
    
    response.download(apkFile);
    

    Documentation for download() is here http://expressjs.com/4x/api.html#res.download. Express works out the correct headers provided the extension of the filename you are sending is '.apk'.

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