在第一篇文章中,我试图用axios调用服务器,它对我很有效。第二篇文章也是如此。
然后在第二个Get中,我得到错误425(太早)。
代码崩溃了。
我该怎么补救?
const handleUpload = async () => {
setIsLoading(true);
if (selectedFile && selectedLanguage) {
const formData = new FormData();
formData.append("file", selectedFile);
formData.append("language", String(selectedLanguage?.code));
try {
const baseURL = process.env.REACT_APP_API_URL;
// First API call to upload the file
const uploadResponse = await axios.post(
`${baseURL}/upload/`,
formData,
{
headers: {
"Content-Type": "multipart/form-data",
},
}
);
const newId = uploadResponse.data.public_id;
setSelectedId(newId);
// Second API call to add translation
const addTranslation = await axios.post(
`${baseURL}/upload/sources/${newId}/outputs`,
{ language: selectedLanguage.code }
);
const newOutputId = addTranslation.data.id;
// Third API call to get the translated content
try {
debugger;
const getTranslation = await axios.get(
`${baseURL}/upload/outputs/${newOutputId}/contents/`
);
const newVideoUrl = getTranslation.data.url;
setVideoUrl(newVideoUrl);
} catch (error) {
console.error("Error fetching translation:", error);
// Handle error specific to fetching translation
}
} catch (error) {
console.error("File upload failed:", error);
// Handle general upload error
} finally {
setIsLoading(false);
}
}
};
字符串
我试着使用settimeout
,分割功能,分割成不同的文件.它没有帮助我。
1条答案
按热度按时间3gtaxfhh1#
由于没有人回答这个问题。我对425网络通信安全性很好奇。
我不知道这是否有用,但值得一试。
如果你在延迟完成后自动重试请求,仍然得到425错误,并继续等待直到响应完成,怎么样?
字符串
这里是retry函数
型
如果您一直收到425错误,那么您可能需要查看服务器日志以查看错误和安全配置