云储存

使用云储存上传文件

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>

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-MFT6azJK-1612678548693)(F:\Uni-app.assets\image-20210207111346248.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-069xYgbC-1612678548698)(F:\Uni-app.assets\image-20210207113956991.png)]

上传并回显
<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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值