strapi:vipsjpeg:输入文件错误的过早末端

发布于 2025-02-03 02:59:54 字数 974 浏览 3 评论 0原文

问题:

从strapi(媒体库(UI))上传图像时,它向我显示了错误: vipsjpeg:输入文件的过早末端

我试图将格式从JPG更改为PNG,但仍然显示出相同的错误。另一方面,我正在使用其他图像(JPG/PNG格式)进行测试。它正确上传。

我想知道错误的原因,以及是否有解决方案。 感谢您的答案

将图像上传到Strapi:媒体库

图像信息

  • jpeg图像-19 kb
  • 尺寸:750×938

“

error:

Error: VipsJpeg: Premature end of input file

config/plugins.js

default配置,提供的,提供由Strapi

module.exports = ({ env }) => ({
  upload: {
    config: {
      breakpoints: {
        xlarge: 1920,
        large: 1000,
        medium: 750,
        small: 500,
        xsmall: 64,
      },
    },
  },
});

Problem:

When uploading an image from Strapi (the Media Library (UI)) it shows me the error: VipsJpeg: Premature end of input file.

I tried to change the format from jpg to png but it still shows the same error. On the other hand, I was testing with other images (jpg/png format). and it uploads correctly.

I would like to know the reason for the error, and if there is any solution.
I will appreciate your answer

Uploading image to strapi: Media Library

Image Info

  • JPEG image - 19 KB
  • Dimensions: 750 × 938

enter image description here

Error:

Error: VipsJpeg: Premature end of input file

config/plugins.js

Default configuration, provided by strapi

module.exports = ({ env }) => ({
  upload: {
    config: {
      breakpoints: {
        xlarge: 1920,
        large: 1000,
        medium: 750,
        small: 500,
        xsmall: 64,
      },
    },
  },
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离旧人 2025-02-10 02:59:54

在遇到此问题时,这似乎是Sharp,Strapi Server停止的问题,因此它返回网络错误502。
要在我的代码中求解它,我必须扩展插件-UPLOAD代码并在该插件中更改此句子以停止导致服务器失败,然后图像可以成功上传,也许没有正确的优化但没有失败。
在node_module/@strapi/plugin-upload/server/services/image-manipulation.js上,将此句子更改

const transformer = sharp();

const transformer = sharp({ failOnError: false });

将其应用于strapi的步骤,将其应用于插件扩展名:

1-扩展插件-Uplopload插件,通过plugin-upload插件。在SRC/Extensions文件夹中创建(上传)文件夹(如果不存在,则创建扩展文件夹)
2-使用此内容创建一个名为(strapi-server.js)的文件,以覆盖image-manupilation服务:

'use strict';

const imageManipulate = require('./server/services/image-manipulation')

module.exports = (plugin) => {

  plugin.services['image-manipulation'] = imageManipulate;

  return plugin;
};

3-复制(utils folder + services/image-manipulation.js),从node_module/@strapi/@strapi/plunin-plugin-upload/server复制到您的扩展文件夹。

4-如前所述,在Image -Manipulation.js中编辑变压器const。


有关尖锐问题的更多信息,请参阅此处: https://github.com/lovell/lovell/sharp/问题/1859

有关扩展Strapi插件的更多信息,请参见: https://docs.strapi.io/ddeveloper-docs/latest/development/plugins-extension.html

It Looks like this is an issue in sharp , Strapi server stop when it encounter this issue and because of that it return network error 502 .
to solve it in my code i had to extend the plugin-upload code and to change this const in that plugin to stop causing server to fail , then image can uploaded successfully , maybe without proper optimization but without failing .
on node_module/@strapi/plugin-upload/server/services/image-manipulation.js change this const

const transformer = sharp();

to this

const transformer = sharp({ failOnError: false });

Steps to Apply it to Strapi as plugin extension :

1 - extend the plugin-upload plugin by creating ( upload ) folder within src/extensions folder ( create extensions folder if it does not exist )
2 - Create a file named ( strapi-server.js ) with this content to overwrite the image-manupilation service :

'use strict';

const imageManipulate = require('./server/services/image-manipulation')

module.exports = (plugin) => {

  plugin.services['image-manipulation'] = imageManipulate;

  return plugin;
};

3 - Copy ( utils folder + services/image-manipulation.js) from node_module/@strapi/plugin-upload/server to your extensions folder .

4 - Edit transformer const in image-manipulation.js as discussed before .


For more information about the sharp issue see here : https://github.com/lovell/sharp/issues/1859

For more information about Extending Strapi Plugin see here : https://docs.strapi.io/developer-docs/latest/development/plugins-extension.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文