I'm trying to use the first express request and response data to the second request, the problem is that both requests need to have their own body data in case I want to use them in the frontend node, is there any efficient approach to solve this issue. in my below requests code, I must use the uploadlink from the first request to the second request.
const ThumbnailUploadlink = async (req, res) => {
const { videoId } = req.body;
const clientServerOptions11 = {
uri: `https://api.vimeo.com/videos/${videoId}/pictures`,
body: JSON.stringify({
name: videoId,
}),
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/vnd.vimeo.*+json;version=3.4',
Authorization: getVimeoAuthorization(),
},
};
request(clientServerOptions11, function (error, response) {
if (error) {
res.send(error);
} else {
const body = JSON.parse(response.body);
res.send(body);
const uploadLink = body.link;
console.log(uploadLink);
}
});
};
// uploadLink must take value from previous request
const ThumbnailUpload = async (req, res, uploadLink) => {
const { selectedFile } = req.body;
const clientServerOptions = {
url: `${uploadLink}`,
body: JSON.stringify({
name1: selectedFile,
}),
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Accept: 'application/vnd.vimeo.*+json;version=3.4',
Authorization: getVimeoAuthorization(),
},
};
request(clientServerOptions, function (error, response) {
if (error) {
res.send(error);
console.log(uploadLink);
} else {
const body = JSON.parse(response.body);
res.send(body);
console.log(uploadLink);
}
});
};