await uniCloud.uploadFile({
filePath: this.avatarUrl,
cloudPath: `user/avatar/${this.userInfo?._id}-${Date.now()}.jpg`,
cloudPathAsRealPath: true,
onUploadProgress: function({
loaded,
total
}) {
var percentCompleted = Math.round((loaded * 100) / total);
uni.showLoading({
title: `正在上传中${percentCompleted}%`
})
},
success(res) {
debugger
callback(res.fileID)
},
fail(err) {
uni.showToast({
icon: "error",
title: '上传失败'
})
},
complete() {
uni.hideLoading()
}
});

4***@qq.com
- 发布:2025-01-15 10:44
- 更新:2025-01-15 14:37
- 阅读:110
产品分类: uniCloud/支付宝小程序云
示例代码:
操作步骤:
await uniCloud.uploadFile({
filePath: this.avatarUrl,
cloudPath: `user/avatar/${this.userInfo?._id}-${Date.now()}.jpg`,
cloudPathAsRealPath: true,
onUploadProgress: function({
loaded,
total
}) {
var percentCompleted = Math.round((loaded * 100) / total);
uni.showLoading({
title: `正在上传中${percentCompleted}%`
})
},
success(res) {
debugger
callback(res.fileID)
},
fail(err) {
uni.showToast({
icon: "error",
title: '上传失败'
})
},
complete() {
uni.hideLoading()
}
});
await uniCloud.uploadFile({
filePath: this.avatarUrl,
cloudPath: `user/avatar/${this.userInfo?._id}-${Date.now()}.jpg`,
cloudPathAsRealPath: true,
onUploadProgress: function({
loaded,
total
}) {
var percentCompleted = Math.round((loaded * 100) / total);
uni.showLoading({
title: `正在上传中${percentCompleted}%`
})
},
success(res) {
debugger
callback(res.fileID)
},
fail(err) {
uni.showToast({
icon: "error",
title: '上传失败'
})
},
complete() {
uni.hideLoading()
}
});
预期结果:
返回URL
返回URL
实际结果:
返回有且fileID
返回有且fileID
4***@qq.com (作者)
老师,求指导
1、如果是图片列表,那岂不是要每个图片都要getTempFileURL?
2、getTempFileURL获取到的地址是有过期时间的,去掉?之后的参数也可以访问,是永久访问吗?那返回这个fileID的作用就是多此一举了吖
2025-01-15 14:40
DCloud_uniCloud_VK
回复 4***@qq.com: 但是私有权限的文件不能去掉?的,只有公共权限的文件可以去掉?所以并不是多此一举
2025-01-15 15:55