l***@163.com
l***@163.com
  • 发布:2023-05-16 09:41
  • 更新:2023-05-16 09:45
  • 阅读:157

【报Bug】云对象写入html string到数据库中,当html string里面含有大图data:base64数据时候,云对象url接口就会报400错误

分类:uniCloud

产品分类: uniCloud/App

示例代码:

云对象代码:

const {
success,
fail
} = require('../../common.js')

module.exports = async function() {
// 获取JQL database引用,此处需要传入云对象的clientInfo,getCount需要额外的数据库api
const dbJQL = uniCloud.databaseForJQL({
clientInfo: this.getClientInfo()
})
const collection = dbJQL.collection('news')

const uid = this.body.id  
const result1 = await collection.doc(uid).get()  
if (result1 && result1.data.length === 0) {  
    fail('未找到该条数据')  
}  

try {  
    const res = await collection.doc(uid).update({  
        title: this.body.title,  
        content: this.body.content,  
        cover_id: this.body.cover_id,  
        type_id: this.body.type_id,  
        published: this.body.published,  
        update_date: new Date().getTime()  
    })  
    return success(res)  
} catch (e) {  
    throw fail('服务器数据错误')  
}  

}

操作步骤:

预期结果:

正常写入数据

实际结果:

Access to XMLHttpRequest at 'https://fc-mp-06c0d67e-341b-4f2d-8cdb-2686a2a70e42.next.bspapp.com/http/updateNewsItem' from origin 'http://localhost:9527' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
xhr.js:160 PUT https://fc-mp-06c0d67e-341b-4f2d-8cdb-2686a2a70e42.next.bspapp.com/http/updateNewsItem net::ERR_FAILED 400

bug描述:

云对象写入富文本编辑中的内容html到数据库中,当html里面含有大图blob:base64数据时候,云对象url接口就会报400错误,并且说跨域错误。如果将大图删除就没有问题。图从网络中直接copy过来的,所以并没有进行上传变成url处理,只是简单的blob数据。

2023-05-16 09:41 负责人:无 分享
已邀请:
piaoyi_UI

piaoyi_UI - 【插件开发】【专治疑难杂症】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=193663(微信搜索飘逸科技UI小程序直接体验)】【骗子请绕道】问题咨询请加QQ群:120594820,代表作灵感实用工具小程序

看报错信息是请求跨域了

  • l***@163.com (作者)

    是的,但是没有地方跨域啊,这里的图片是从网络上copy过来的图片数据,并没有url

    2023-05-16 10:17

  • piaoyi_UI

    回复 l***@163.com: 400可能是请求体太大了,看能不能设置后端那个限制大一点

    2023-05-16 10:21

  • l***@163.com (作者)

    回复 piaoyi_UI: 我用的uniCloud 自带的数据库。在哪里能设置大小呢?

    2023-05-16 10:27

  • piaoyi_UI

    回复 l***@163.com: 不是数据库问题

    2023-05-16 10:29

  • l***@163.com (作者)

    回复 piaoyi_UI: 应该是请求体太大了,我们以前做过的项目,也是这样做的,但是后端不知道咋弄的,就没有问题。uniCloud就限制死了

    2023-05-16 10:53

要回复问题请先登录注册