wx.uploadVoice 如何上传到服务器
时间: 2023-07-30 12:12:00 浏览: 64
wx.uploadVoice 是微信小程序中用于上传语音文件到服务器的API,具体的使用方法如下:
1. 首先在小程序页面中处理好用户录制好的语音文件,并获取到语音文件的临时路径 tempFilePath。
2. 调用 wx.uploadVoice 方法,将语音文件上传到服务器。该方法接受以下参数:
- 参数名:localId,类型:String,必填项,表示需要上传的语音文件的本地ID,由wx.startRecord或wx.chooseVoice返回的临时文件路径。
- 参数名:isShowProgressTips,类型:Number,非必填项,表示是否显示上传进度提示,默认为1,表示显示。
- 参数名:success,类型:Function,非必填项,表示上传成功的回调函数。
- 参数名:fail,类型:Function,非必填项,表示上传失败的回调函数。
- 参数名:complete,类型:Function,非必填项,表示上传完成的回调函数。
3. 在上传成功的回调函数中,可以获取到服务器返回的语音文件的serverId,可以将serverId保存到数据库中,以便后续使用。
示例代码如下:
```
wx.uploadVoice({
localId: tempFilePath,
isShowProgressTips: 1,
success: function (res) {
var serverId = res.serverId; // 上传成功后获取到的语音文件的serverId
// 将serverId保存到数据库中,以便后续使用
},
fail: function (res) {
console.log(res);
}
});
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)