Strapi:将图像上传到Strapi,图像不会渲染
问题
我想知道您是否可以帮助确定与将图像上传到thumb
属于content-type 目录
的问题。
图像图像在Strapi面板中呈现后不会呈现,它仅显示名称。
const getFileSize = (filePath) => {
return statSync(filePath)["size"]; // statSync from `fs-extra` library
};
strapi.service("api::directory.directory").create({
data: {},
files: {
thumb: {
path: `${imagesDir}/Crab-1-1-scaled.jpg`,
name: "Crab-1-1-scaled.jpeg",
type: mime.lookup(`${imagesDir}/Crab-1-1-scaled.jpg`), // mime from `mime-types` library
size: getFileSize(`${imagesDir}/Crab-1-1-scaled.jpg`),
},
},
});
console.log
size
在上传数据时始终为零
{
files: {
thumb: {
path: 'src/scripts/Directory/images/Crab-1-1-scaled.jpg',
name: 'Crab-1-1-scaled.jpeg',
type: 'image/jpeg',
size: 0
}
}
}
输出
,图像未渲染,仅显示图像的名称。
Problem
I would like to know if you can help identify the issue related to uploading an image to the thumb
field belonging to the content-type Directory
.
The image image does not render once it is in the strapi panel, it only shows the name.
const getFileSize = (filePath) => {
return statSync(filePath)["size"]; // statSync from `fs-extra` library
};
strapi.service("api::directory.directory").create({
data: {},
files: {
thumb: {
path: `${imagesDir}/Crab-1-1-scaled.jpg`,
name: "Crab-1-1-scaled.jpeg",
type: mime.lookup(`${imagesDir}/Crab-1-1-scaled.jpg`), // mime from `mime-types` library
size: getFileSize(`${imagesDir}/Crab-1-1-scaled.jpg`),
},
},
});
console.log
size
is always zero
{
files: {
thumb: {
path: 'src/scripts/Directory/images/Crab-1-1-scaled.jpg',
name: 'Crab-1-1-scaled.jpeg',
type: 'image/jpeg',
size: 0
}
}
}
output
When uploading the data the image is not rendered, it only shows the name of the image.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在Strapi 4中所做的是:我首先使用内置上传插件,该插件返回上传文件的ID。然后,我使用ID创建/更新我的实体(在您的情况下 Directory )。
这是您可以使用的工作代码段:
What I do in Strapi 4 is this: I first use the built-in upload plugin, which returns an id of the uploaded file. I then use the id to create/update my entity (Directory in your case).
Here is a working code snippet you can use: