index.vue
<template>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title">{{title}}</text>
</view>
<button @click="open">执行云函数</button>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello'
}
},
onLoad() {
},
methods: {
open(){
uni.chooseImage({
count:1, //设置数量
success(res) {
//获取文件路劲
const temFilePath=res.tempFilePaths[0]
console.log(temFilePath);
//获取文件名
const temFileName=res.tempFiles[0].name
console.log(temFileName);
uniCloud.uploadFile({
filePath:temFilePath,
cloudPath:temFileName,
success() {
console.log(res);
},fail(err) {
console.log(err);
}
})
},
fail(err) {
console.log(err);
}
})
}
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>
上传并回显
<template>
<view class="content">
<image class="logo" :src="src"></image>
<view class="text-area">
<text class="title">{{title}}</text>
</view>
<button @click="open">执行云函数</button>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello',
src:''
}
},
onLoad() {
},
methods: {
open(){
let self=this
uni.chooseImage({
count:1, //设置数量
success(res) {
//获取文件路劲
const temFilePath=res.tempFilePaths[0]
//console.log(temFilePath);
//获取文件名
const temFileName=res.tempFiles[0].name
//console.log(temFileName);
uniCloud.uploadFile({
filePath:temFilePath,
cloudPath:temFileName,
success(res) {
console.log(res);
self.src=res.fileID;
console.log(res.fileID)
},fail(err) {
console.log(err);
}
})
},
fail(err) {
console.log(err);
}
})
}
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>
删除
<template>
<view class="content">
<image class="logo" :src="src"></image>
<view class="text-area">
<text class="title">{{title}}</text>
</view>
<button @click="open">执行云函数</button>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello',
src:''
}
},
onLoad() {
},
methods: {
open(){
//let self=this
// uni.chooseImage({
// count:1, //设置数量
// success(res) {
// //获取文件路劲
// const temFilePath=res.tempFilePaths[0]
// //console.log(temFilePath);
// //获取文件名
// const temFileName=res.tempFiles[0].name
// //console.log(temFileName);
// uniCloud.uploadFile({
// filePath:temFilePath,
// cloudPath:temFileName,
// success(res) {
// console.log(res);
// self.src=res.fileID;
// console.log(res.fileID)
// },fail(err) {
// console.log(err);
// }
// })
// },
// fail(err) {
// console.log(err);
// }
// })
//删除文件
uniCloud.deleteFile({
fileList:['https://vkceyugu.cdn.bspapp.com/VKCEYUGU-b779afdf-c6d2-46a0-a25b-3687614f0125/4215afaf-bdd2-436f-adc4-1a7778f33d7b.png'],
success(res) {
console.log(res)
},fail(err) {
console.log(err)
}
})
}
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>