weixin_43304117 2018-09-28 10:04 采纳率: 0%
浏览 2972

微信小程序录音上传返回 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条回答 默认 最新

  • 韩小布 2018-10-22 02:45
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决