1***@qq.com
1***@qq.com
  • 发布:2024-02-22 19:48
  • 更新:2024-02-23 10:21
  • 阅读:903

微信小程序 [渲染层网络层错误]

分类:uniCloud

[渲染层网络层错误] 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  
};  
】
2024-02-22 19:48 负责人:无 分享
已邀请:
JXWang

JXWang

uniCloud.uploadFile的返回值fileID是文件唯一 ID,用来访问文件,不能作为url直接访问,需再调用uniCloud.getFileInfo方法获取到url即为图片的cdn链接,才能直接访问。 详见文档

要回复问题请先登录注册