Code: Select all
***This is the api i wrote***app.get('/', async (req, res) => {
const auth = { username: 'username', password: 'password' };
const { path } = req.query;
try {
const result = await fileDownload(auth, path);
console.log(result);
// Handle the result
res.status(200).send(result);
} catch (err) {
console.error(err);
res.status(400).send({ message: err.message ? err.message : err });
}
});
const fileDownload = async (auth, path) => {
try {
const result = await download(auth, path);
console.log(result, 'file download success');
return result;
} catch (err) {
throw err;
}
};
const download = async (auth, path) => {
try {
const base_url = 'http://localhost/OpenKM/frontend/Download';
//const url = 'documentdownload';
const fullPath = `${base_url}?docPath=${encodeURIComponent(path)}`;
const response = await axios.get(fullPath, {
auth: {
username: auth.username,
password: auth.password
},
responseType: 'arraybuffer'
});
return response.data;
} catch (err) {
throw err;
}
};
it is downloading as a binary format, but i don't know which is correct one or not . and can you correct me this code.Please do the needful asap.
Thanks.