You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.3 KiB
50 lines
1.3 KiB
Page({
|
|
// 上传图片
|
|
doUpload: function () {
|
|
// 选择图片
|
|
wx.chooseImage({
|
|
count: 1,
|
|
sizeType: ['compressed'],
|
|
sourceType: ['album', 'camera'],
|
|
success: function (res) {
|
|
wx.showLoading({
|
|
title: '上传中',
|
|
})
|
|
|
|
const filePath = res.tempFilePaths[0]
|
|
|
|
// 上传图片
|
|
const cloudPath = `my-image${filePath.match(/\.[^.]+?$/)[0]}`
|
|
wx.cloud.uploadFile({
|
|
cloudPath,
|
|
filePath,
|
|
success: res => {
|
|
console.log('[上传文件] 成功:', res)
|
|
|
|
app.globalData.fileID = res.fileID
|
|
app.globalData.cloudPath = cloudPath
|
|
app.globalData.imagePath = filePath
|
|
|
|
wx.navigateTo({
|
|
url: '../storageConsole/storageConsole'
|
|
})
|
|
},
|
|
fail: e => {
|
|
console.error('[上传文件] 失败:', e)
|
|
wx.showToast({
|
|
icon: 'none',
|
|
title: '上传失败',
|
|
})
|
|
},
|
|
complete: () => {
|
|
wx.hideLoading()
|
|
}
|
|
})
|
|
},
|
|
fail: e => {
|
|
console.error(e)
|
|
}
|
|
})
|
|
}
|
|
})
|
|
|