尝试将图像上传到Strapi时400个错误
我在配置文件中有一个轮播,当我编辑配置文件数据时,并上传了现有的图像,我会从strapi中获得400个错误,但是如果我添加了新图像,一切都很好,但是先前的图像已删除!
这是后端图像上的代码:
var formData = new FormData();
imgs.forEach((img) => {
formData.append('files', img);
});
formData.append('data', JSON.stringify(inputData));
return _post({
name: 'uploadImages_NewOrder',
endpoint: '/new-orders',
isForm: true,
sendData: formData,
});
这是strapi代码:
let profile = await getProfile(ctx);
await strapi.plugins.upload.controllers.upload.upload(ctx);
profile = await strapi.services['profile'].update({ id: profile.id }, { carousel: ctx.body });
ctx.body = pluckData(sanitizeEntity(profile, { model: strapi.models.profile }));
// return error
return 'ok';
我认为这个问题是因为对于现有图像,它已被发送为JSON对象而不是文件对象。
I have a carousel in the profile, when I'm editing profile data the and uploading the existing images I'm getting 400 error from Strapi, but if I added new images everything going well but the previous images are deleted!
This is the code on the image to the backend:
var formData = new FormData();
imgs.forEach((img) => {
formData.append('files', img);
});
formData.append('data', JSON.stringify(inputData));
return _post({
name: 'uploadImages_NewOrder',
endpoint: '/new-orders',
isForm: true,
sendData: formData,
});
and this is strapi code:
let profile = await getProfile(ctx);
await strapi.plugins.upload.controllers.upload.upload(ctx);
profile = await strapi.services['profile'].update({ id: profile.id }, { carousel: ctx.body });
ctx.body = pluckData(sanitizeEntity(profile, { model: strapi.models.profile }));
// return error
return 'ok';
I think this problem is because for the existing images it's been sent as json object not File object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论