'How to get client to download file from a page that's password protected?
I have an FTP server that's password protected. I want users of my site to be able to download from the FTP server by clicking on a button, and they are not allowed to know the password. I've been using puppeteer to get through the authentication but as the code is written on the server it downloads to my server instead of on the client. This is the code:
async function run() {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.authenticate({username:theUsername, password:thePassword});
await page.goto(theURL);
browser.close();
return page;
}
run();
res.send();
The above works but it launches a chromium on the back-end and the file get's downloaded to the filesystem which is not what I want.The front end is written using vue and for some reason I can't download puppeteer on the front end. Is there any other way to accomplish this?
Solution 1:[1]
You can securely send passwords from client-side by using environment variables. Information on that here: https://dev.to/deammer/loading-environment-variables-in-js-apps-1p7p
Keep in mind for Vue specifically you need to prefix environment variables. So instead of MY_VAR, you need to attach VUE_APP_ to everything, so it will be VUE_APP_MY_VAR.
await page.authentication({ username: process.env.VUE_APP_USERNAME, password: process.env.VUE_APP_PASSWORD })
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Arc |
