尝试将图像上传到Strapi时400个错误

发布于 2025-02-02 18:45:51 字数 801 浏览 3 评论 0原文

我在配置文件中有一个轮播,当我编辑配置文件数据时,并上传了现有的图像,我会从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文