【已解决】 服务端的地址写法有误 导致不能接受
1.菜鸡写的小程序 中间也是血泪无数 望大神解答疑惑
2.代码如下
JS
//index.js
//获取应用实例
const app = getApp()
const recorderManager = wx.getRecorderManager()
const innerAudioContext = wx.createInnerAudioContext()
var tempFilePath
var num = 0
var getPathArr = tempFilePath;
Page({
data: {
audioText: 'lalalalal',
btn_Text: '开始录音',
clickType: 'primary',
disType: ''
},
//开始录音的时候
startAudio: function() {
const options = {
duration: 120000, //指定录音的时长,单位 ms
sampleRate: 16000, //采样率
numberOfChannels: 1, //录音通道数
encodeBitRate: 96000, //编码码率
format: 'acc', //音频格式,有效值 aac/mp3
frameSize: 50, //指定帧大小,单位 KB
}
//开始录音
recorderManager.start(options);
recorderManager.onStart(() => {
console.log('recorder start')
})
//错误回调
recorderManager.onError((res) => {
console.log(res);
})
//变形
num++;
var result = num + 1;
if (num == 0) {
this.setData({
btn_Text: '开始录音',
clickType: 'primary',
disType: ''
})
} else {
this.setData({
btn_Text: '重新录音',
clickType: 'warn',
disType: 'true'
})
}
},
//停止录音
stopAudio: function() {
recorderManager.stop();
recorderManager.onStop((res) => {
this.tempFilePath = res.tempFilePath;
console.log('停止录音', res.tempFilePath)
const {
tempFilePath
} = res
}, );
this.setData({
disType: ''
})
},
//播放声音
playAudio: function() {
innerAudioContext.autoplay = true
innerAudioContext.src = this.savedFilePath,
innerAudioContext.onPlay(() => {
console.log('开始播放')
})
innerAudioContext.onError((res) => {
console.log(res.errMsg)
console.log(res.errCode)
})
},
upload: function() {
wx.request({
url: 'http://127.0.0.1:5000/upload',
data: {
audioText: 'lalalalal'
},
header: {
'content-type': 'text/html'
},
success: function(res) {
console.log(res.data)
}
})
wx.uploadFile({
url: 'http://127.0.0.1:5000/upload',
filePath: this.tempFilePath + "",
name: 'the_file',
header: {
"Contect-Type": "mutipart/form-data"
},
formData: {
'the_file': 'Music'
},
success: function(res) {
console.log(res);
wx.showToast({
title: 'OK',
icon: 'success',
duration: 2000
})
},
fail: function(res) {
console.log(res)
},
complete: function(res) {
}
})
},
onLoad: function(options) {
console.log(recorderManager)
},
longPress: function() {
console.log('longTap....')
},
touchStart: function() {
console.log('touchStart....')
this.startAudio();
},
touchEnd: function() {
console.log('touchEnd....')
this.stopAudio()
},
})
一样的报错 我的是上传图片然后提示500