我在小程序中调用api录音,然后把录音文件上传到nodejs,成功后我想看一下录音文件,点开结果发现文件打不开
小程序代码:
// 结束录音
voiceEnd(e){
if(this.data.voiceShow != true) return
const that = this
recorderManager.stop()
recorderManager.onStop(async (res) => {
console.log('录音停止', res)
// tempFilePath = res.tempFilePath
this.setData({
tempFilePath:res.tempFilePath
})
innerAudioContext.src = res.tempFilePath
var uploadTask = wx.uploadFile({
filePath: res.tempFilePath,
name: 'voiceFile',
url: 'http://localhost:3000/api/voice',
header: {
"Content-Type": "multipart/form-data"
},
success:(e) => {
console.log('success',e);
},
fail: (e) => {
console.log('fail',e);
}
});
uploadTask.onProgressUpdate((e) => {
console.log(e);
console.log('期望上传的总字节数:' + e.totalBytesExpectedToSend);
console.log('已经上传的字节数' + e.totalBytesSent);
})
})
},
nodejs代码:
const express = require('express')
const ffmpeg = require('ffmpeg')
const router = express.Router()
const multer = require('multer')
// let upload = multer({ dest: 'routers/voiceup' })
// 处理上传文件时需要的数据
const { cutOutStr } = require('../utils/index')
const moment = require('moment')
let date = new Date()
let times = date.getTime()
let originalname;
let random = Math.floor(Math.random() * (1000 - 100 + 1)) + 100
let urlStr;
let src = ''
let storage = multer.diskStorage({
destination: function(req, file, cb) {
cb(null, 'routers/voiceup');
},
filename: function(req, file, cb) {
originalname = Buffer.from(file.originalname, "latin1").toString("utf8"); // 解决接收文件的文件名中文乱码问题
urlStr = originalname
times = date.getTime()
random = Math.floor(Math.random() * (10000 - 100 + 1)) + 100
src = 'http://localhost:3000/' + urlStr
cb(null, urlStr)
}
})
let upload = multer({ storage: storage });
router.post('/',upload.single('voiceFile'),(req,res) => {
try {
console.log('asssssssssssssssssssssss');
console.log('received',req.file);
// ffmpeg
res.send({code:200,msg:'上传成功'})
} catch(err) {
console.log(err);
res.status(500).send(err)
}
})
module.exports = router
这是为什么啊?有没有大锅帮忙看一下