I'm working with the tiktok API for web and I ran into a problem. When I went looking for the solution, I found several similar ones on StackOverflow. So I came here to share with you my solution, when I found the reason for my problem. In my case, the video was sent and appeared in the notifications, but then it gave an error saying that the video (It was not loaded). the problem was that the request was being sent even before loading the entire file
file completely with fs.createReadStream(<file>).
So I added an await setTimeout() - delay to check. and it worked.
private seedVideo = (fileVideo, url_share_video): Promise<any> => {
return new Promise( async (resolve, reject) => {
const formData = new FormData();
// function assync
// const bufferFile = await this.readFileAsync(fileVideo);
formData.append('video', createReadStream(fileVideo));
await setTimeout(5000) // delay for test
const res = await axios.post(url_share_video, formData, {
headers: formData.getHeaders()
})
.then((res) => {
resolve(res.data);
})
.catch((err) => {
console.log("ERROR append video to upload", err.response.data);
reject(err.response.data);
})
})
}
If this is also your problem. Just create a function or a mechanism to read the file asynchronously.