微信小程序录音上传返回 statusCode: 500

【已解决】 服务端的地址写法有误 导致不能接受

1.菜鸡写的小程序 中间也是血泪无数 望大神解答疑惑

wx.request正常上传的
但是录音文件无法上传
图片说明

图片说明

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()
  },
})

1个回答

一样的报错 我的是上传图片然后提示500

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问