欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 建筑 > uniapp在开发app时上传文件时的问题

uniapp在开发app时上传文件时的问题

2024/10/25 13:29:24 来源:https://blog.csdn.net/wzwzwz555/article/details/142167223  浏览:    关键词:uniapp在开发app时上传文件时的问题

手机拍照然后上传没问题 但是在相册中选择的照片上传 ios手机不行 安卓一部分手机也点击没反应
最后对比了下参数 发现路径有所不同
使用uni.saveFile保存路径好在重新上传

  saveFileSync(tempFilePath){return new Promise((resolve, reject) => {uni.saveFile({tempFilePath,success: function (file) {resolve(file.savedFilePath)},fail: function (error) {reject(error)}})})},
    uni.chooseImage({count: 1, //默认9sizeType: ["compressed"], //可以指定是原图还是压缩图,默认二者都sourceType: ['camera','album'], success: async function(result) {let ewm = result.tempFiles[0]const path = await that.saveFileSync(ewm.path)if (result.errMsg === "chooseImage:ok") {result.tempFiles[0].path=path// that.upload(path);that.upload(result.tempFiles[0]);} else {uni.showToast({title: "图片上传失败",icon: "none",});}},fail(err) {uni.showToast({title: "取消上传",icon: "none",});},});
Upload(event) {const token = this.getToken();// const url = this.getuploadUrl();const imgList = [];uni.showLoading({title: "上传中...",mask: true,});try {const [err, res] = await uni.uploadFile({url: `${HOST}/resource/file/upload`,filePath: event.path,name: "file",header: {Authorization: token,},});if (res && (res.statusCode === 200)) {const result = JSON.parse(res.data);if (result.code == 200) {let res1 = JSON.parse(res.data);res1.data.uuid = res1.data.id;res1.data.paramskey = event.name;imgList.push(res1.data);const list = [...this.list, ...imgList];this.$emit("value", list);this.$emit("change", list);this.$emit("upload", imgList);} else {wx.showToast({icon: "none",title: result.msg,});}} else {wx.showToast({icon: "error",title: "上传失败",});}} catch (error) {console.log(error)}uni.hideLoading();this.$emit("upload", imgList);},

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com