[渲染层网络层错误] Failed to load local image resource /pages/shehui/cloud://env-00jxgdzz0ma2/images/1708601818886.png
the server responded with a status of 500 (HTTP/1.1 500 Internal Server Error)
(env: Windows,mp,1.06.2401020; lib: 3.3.3)
<template>
<view>
<input type="text" v-model="title" placeholder="请输入标题">
<input type="text" v-model="content" placeholder="请输入内容">
<button @click="chooseImage">选择图片</button>
<img v-if="imageUrl" :src="imageUrl" style="max-width: 100%">
<button @click="submit">提交</button>
</view>
</template>
<script>
export default {
data() {
return {
title: '',
content: '',
imageUrl: ''
}
},
methods: {
chooseImage() {
uni.chooseImage({
count: 1,
success: (res) => {
const tempFilePath = res.tempFilePaths[0]
this.uploadImage(tempFilePath)
}
})
},
uploadImage(filePath) {
const cloudPath = 'images/' + Date.now() + filePath.match(/\.[^.]+$/)[0]
uniCloud.uploadFile({
cloudPath,
filePath,
success: (res) => {
this.imageUrl = res.fileID
},
fail: (err) => {
console.error('图片上传失败', err)
}
})
},
submit() {
uniCloud.callFunction({
name: 'getbkfabu',
data: {
title: this.title,
content: this.content,
imageUrl: this.imageUrl
},
success: (res) => {
console.log('发布成功', res)
},
fail: (err) => {
console.error('发布失败', err)
}
})
}
}
}
</script>
云函数【'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
const collection = db.collection('bkfabu')
const { title, content, imageUrl } = event
const res = await collection.add({
title,
content,
imageUrl,
createTime: new Date().getTime()
})
return res
};
】