I am using facebook authentication and want to save user avatar from url to a folder on the server. The user avatar is stored in my variable ${picture}
await mkdir(`${dir}/dist/users/${insertId}`)
if (!facebookLogin) {
fs.createReadStream(`${dir}/dist/images/users.jpg`).pipe(
fs.createWriteStream(`${dir}/dist/users/${insertId}/avatar.jpg`)
)
}
else {
fs.createReadStream(`${picture}`).pipe(
fs.createWriteStream(`${dir}/dist/users/${insertId}/avatar.jpg`)
)
}
The part that is NOT working is in the ELSE LOOP (facebook login user) fs.createReadStream('${picture}') as this tries to fecth it from C:\xampp\htdocs\https:\platform-lookaside.fbsbx.com\platform\profilepic\?..........
I want it to directly copy from https:\platform-lookaside.fbsbx.com\platform\profilepic\?.............
May be I should not use fs.createReadStream as the image is in a url now. How can I change this to copy image fro url to server?