我使用以下模式创建了一个用于练习目的的自定义插件
"attributes": {
"name": {
"type": "string"
},
"image": {
"type": "media",
"allowedTypes": [
"images",
"files",
"videos",
"audios"
],
"multiple": true
},
"price": {
"type": "string"
}
}
我的服务看起来像这样
async create(data){
// console.log(data.files)
const parsedData = JSON.parse(data.body.data)
// console.log(data.body.data)
return strapi.entityService.create("plugin::shoes.shoe",{
data:{
...parsedData
},
files:{
file: data.files['files.image']
}
})
},
这就是我正在测试从前端访问 API 的内容。
const testInput=async (e)=>{
e.preventDefault()
const data = {
name:"test",
price:"100"
}
formData.append('data', JSON.stringify(data))
formData.append('files.image', e.target.files[0])
const request = await fetch('http://localhost:1337/shoes/create',{
method:"POST",
body: formData
})
}
图像成功上传到媒体库,其他属性。唯一的问题是图像没有链接到内容类型。它看起来像这样。
如果我做错了什么,将不胜感激。
我在没有创建自定义插件的情况下尝试过这个,因为直接从 strapi 创建内容类型,它工作正常。但是当我尝试使用自定义插件时,我不知道为什么没有链接图像。我在寻找与此相关的资源,但其中大多数都没有涵盖自定义插件(或者我搜索了错误的东西)
谢谢