0
点赞
收藏
分享

微信扫一扫

上传到七牛

<template>
<view>
<button type="default" @click="startupload()">上传到七牛</button>
</view>
</template>

<script>
export default {
data() {
return {

}
},
methods: {
startupload() {

uni.chooseImage({
count: 1,
success: (chooseImageRes) => {
const tempFilePaths = chooseImageRes.tempFilePaths;

var token ="qHnX_g5"
uni.uploadFile({
url: "https://upload-cn-east-2.qiniup.com",
filePath: tempFilePaths[0],
name: 'file',
method: "POST",
formData: {
"key": new Date().getTime()+Math.random(),
"token": token,
},
success: uploadFileRes => {
let strToObj = JSON.parse(uploadFileRes.data)
console.log("===========key=========")
console.log(strToObj.key)
// http://qiniu.gugenst.cn/1664507096392.08
},
fail: fail => {
console.log(fail)
uni.showToast({
title: "网络错误",
icon: "none"
});
}
})


}
});
}
}
}
</script>

<style>

</style>

举报

相关推荐

0 条评论