小程序 uploadFile:fail createUploadTask:fai
发布于 6 年前 作者 yongjin 5382 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)
  • 预期表现

图片和video的上传发布功能,在安卓系统上可正常操作,IOS上首次使用时发布会出现这个报错,关了微信重新打开时图片可以正常发布,video只能拍摄发布,不能选择本地的,TLS版本是1.2版本的,服务器域名等也配置正确。

  • 复现路径

  • 提供一个最简复现 Demo

/**

  * 选择发布img或video

  */

uploadFiles() {

const than = this;

wx.showActionSheet({

itemList: [‘选择img’, ‘选择video],

success: function (e) {

const list = than.data.imgListArr;

const bool = (list.length > 0 && e.tapIndex === 1) || (than.data.videoUrl > 0 && e.tapIndex === 0);

if (bool) {

util.showModel(‘发布失败’, video和图片不能一起上传’);

return;

}

if (e.tapIndex === 0) {

// 选择图片

wx.chooseImage({

sizeType: [‘compressed’],

success(res) {

let newImglist = [];

res.tempFilePaths.map((item, index) => {

const url = util.apiUrl.url + ‘/wxapp/Common/doWechatPic’;

const uploadTask = wx.uploadFile({

url,

filePath: item,

name: ‘file’,

success(ittl) {

let data = ittl.data;

let da = {};

data = data.replace(" ", “”);

data = data.replace(/\ufeff/g, “”);

if (typeof data != ‘object’) {

data = data.replace(/\ufeff/g, “”);//重点

da = JSON.parse(data);

}

newImglist = newImglist.concat(da.image_urls[0]);

than.setData({

imgVideoBool: e.tapIndex,

imgListArr: newImglist,

videoUrl: ‘’

});

}

});

uploadTask.onProgressUpdate((res) => {

console.log(res);

let progress = res.progress;

if (progress < 100) {

than.setData({

showLoading: true

})

} else {

setTimeout(function () {

than.setData({

showLoading: false

})

}, 3000)

}

})

});

}

});

return;

} else if (e.tapIndex === 1) {

// video

wx.chooseVideo({

sourceType: [‘album’, ‘camera’],

maxDuration: 60,

camera: ‘back’,

success(res) {

console.log(res);

const url = util.apiUrl.url + ‘/wxapp/Common/upload_aliyun_video’;

const uploadTask2 = wx.uploadFile({

url, //仅为示例,非真实的接口地址

filePath: res.tempFilePath,

name: ‘file’,

success(ittl) {

console.log(ittl);

let data = ittl.data;

let da = {};

data = data.replace(" ", “”);

data = data.replace(/\ufeff/g, “”);

if (typeof data != ‘object’) {

data = data.replace(/\ufeff/g, “”);//重点

da = JSON.parse(data);

}

than.setData({

imgVideoBool: e.tapIndex,

imgListArr: [],

videoUrl: da.video_url

});

}

})

uploadTask2.onProgressUpdate((res) => {

let progress = res.progress;

if (progress < 100) {

wx.showLoading({

title: ‘上传中…’,

})

} else {

setTimeout(function () {

wx.hideLoading()

}, 500)

}

})

}

});

}

}

});

},

1 回复

检查一下域名配置是否正确:

回到顶部