reactjs - How to increase timeout for Axios call [React]
问题描述
I'm trying to increase the timeout of an axios call. Unfortunately, because I am doing some ffmpeg conversation, it seems the call is timedout before the process can be done. Below are the console lines. where "file has been converted successful" is the completion of the backend process, and you can see /downloadShare is returned before.
Any idea if I'm doing it right? Code block below.
GET / 200 0.466 ms - 18
GET / 200 0.392 ms - 18
GET /downloadShare?id=xxxxxx - - ms - -
GET / 200 0.408 ms - 18
GET / 200 0.411 ms - 18
GET /downloadShare?id=xxxxx - - ms - -
GET / 200 0.410 ms - 18
GET / 200 0.395 ms - 18
GET / 200 0.396 ms - 18
GET / 200 0.433 ms - 18
file has been converted successfully
GET / 200 0.672 ms - 18
GET / 200 0.588 ms - 18
GET / 200 0.430 ms - 18
file has been converted succesfully
My code
const url = `${ConfigMain.getBackendURL()}/downloadShare?id=${id}`;
return Axios.get(url,{
timeout:100000
})
.then(response => {
console.log('aaaaa', response);
return response.data
})
.catch(e => {
return []
});
解决方案
要增加 axios 超时,您可以创建一个 axios 实例,然后设置所需的超时
const api = axios.create({
baseURL: url,
timeout: '8000ms',
});
要进行 API 调用,您可以像这样使用创建的 axios 实例,
api.get(url)
推荐阅读
- kubernetes - 除了与 Hana 紧密耦合之外,Kubernetes pod 还可以扩展吗?
- redirect - 在 Netlify 上将 HTTP 站点移动到 HTTPS - 301 重定向和 SEO
- javascript - 是否有更简单(更短)的符号来用 Javascript 编写这个点击事件/函数?
- python - 直方图`bins`必须单调增加matplotlib
- java - 是否需要安装 JDK 才能在 atom 文本编辑器中运行 java 代码?
- android - Android Studio 中用于制作基于机器学习模型的应用程序的最低 SDK(软件开发工具包)级别是多少
- python - 我需要帮助我的 YouTube 视频下载器在 Python 中使用 tkinter 和 pytube
- ios - 在 SwiftUI 中使用 Kotlin 多平台类
- javascript - 如果逗号是对象中的最后一项,则删除它
- uvm - x.stop_sequences() 导致这个 UVM FATAL Item_done() 在没有未完成请求的情况下被调用