用miniprogram-file-uploader上传需要分片的文件卡在start upload?
使用miniprogram-file-uploader上传需要分片的文件卡在 start upload chunks,上传一个不需要分片的文件倒是可以上传成功。 这种情况只在真机调试的时候出现,在模拟器上上传完全没问题。 文件代码基本拷贝miniprogram-file-uploader代码仓库中的例子。 [图片] 这是真机调试的控制台信息截图 最开始的部分是使用这个控件进行图片上传,成功了,第二个部分是使用wx.upload上传一个9M多的视频也成功了,最后一个部分是使用这个控件进行视频上传,卡在这里不动了,并且右侧连接信息下面出现连接错误。 上传页面js代码 // pages/upload/upload.js
// 文件上传 参考 https://github.com/wechat-miniprogram/miniprogram-file-uploader/tree/0c69766a4c5c4a2a6194c4f80479aabe39121c5e
import Uploader from '../../miniprogram_npm/miniprogram-file-uploader/index'
const app = getApp()
const MB = 1024 * 1024
const HOST_IP = '192.168.31.27'
const MERGE_URL = `http://${HOST_IP}:5001/Plugin/WeAppApi/upload/merge`
const VERIFY_URL = `http://${HOST_IP}:5001/Plugin/WeAppApi/upload/verify`
const UPLOAD_URL = `http://${HOST_IP}:5001/Plugin/WeAppApi/upload/upload`
Page({
/**
* 页面的初始数据
*/
data: {
progress: 0,
uploadedSize: 0,
averageSpeed: 0,
timeRemaining: Number.POSITIVE_INFINITY,
testChunks: false,
url: `http://${HOST_IP}:5001/upload/211206161410.mp4`
},
/**
* 生命周期函数--监听页面加载
*/
onLoad() {
this.chunkSize = 5 * MB
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
onTestChunksChange(e) {
const value = e.detail.value
this.data.testChunks = value
},
async chooseVideo() {
this.reset()
const {
tempFilePath,
size,
} = await wx.chooseVideo({
sourceType: ['album','camera'],
compressed: false
})
console.log(tempFilePath)
if (!Uploader.isSupport()) {
wx.showToast({
title: '分片上传在 2.10.0 版本以上支持',
icon: 'none',
duration: 3000
})
return
}
const uploader = new Uploader({
tempFilePath,
totalSize: size,
fileName: tempFilePath,
verifyUrl: VERIFY_URL,
uploadUrl: UPLOAD_URL,
mergeUrl: MERGE_URL,
testChunks: this.data.testChunks,
verbose: true
})
uploader.on('retry', (res) => {
console.log('retry', res.url)
})
uploader.on('complete', (res) => {
console.log('upload complete', res)
})
uploader.on('success', (res) => {
console.log('upload success', res)
this.setData({
url: `http://${HOST_IP}:5001/${res.url}`
})
})
uploader.on('fail', (res) => {
console.log('upload fail', res)
})
uploader.on('progress', (res) => {
this.setData({
progress: res.progress,
uploadedSize: parseInt(res.uploadedSize / 1024),
averageSpeed: parseInt(res.averageSpeed / 1024),
timeRemaining: res.timeRemaining
})
})
uploader.upload()
this.uploader = uploader
},
reset() {
this.setData({
progress: 0,
uploadedSize: 0,
averageSpeed: 0,
timeRemaining: Number.POSITIVE_INFINITY,
})
},
handleUpload() {
this.uploader && this.uploader.upload()
},
handlePause() {
this.uploader && this.uploader.pause()
},
handleResume() {
this.uploader && this.uploader.resume()
},
handleCancel() {
this.uploader && this.uploader.cancel()
}
})