带有锐利调整大小图像的nodejs导致content_length_mismatch 200错误

问题描述

这是我的图片尺寸调整上传代码。 (nodjs聊天程序) 但我遇到了色度问题,即边缘浏览器问题。(桌面) devtools说“ net :: ERR_CONTENT_LENGTH_MISMATCH 200(确定)” 图像文件调整大小并保存文件 但在浏览器中显示损坏的图像,因此我刷新浏览器,然后显示图像。 小图片文件上传还可以,但是大图片文件有时会出现问题(超过1,2〜10mb) 因此,我删除了大幅调整代码大小的行。没关系。 有人知道吗?

const imageUpload = async(data) => {
const { IMAGEPATH } = require('../path');

let extras = {};

if (data.messageData.message.extras) {
    for (let i = 0; i<data.messageData.message.extras.length; i++) {
        const FileName = data.messageData.channel + '/' + Date.Now() + i + ".png";

        await fs.writeFileSync(IMAGEPATH + data.chat.path + FileName,data.messageData.message.extras[i],"binary",(err) => {
            if (err) throw err;
        });

        await sharp(IMAGEPATH + data.chat.path + FileName)
            .rotate()
            .resize({
                width: 800
            })
            .toBuffer((err,buffer) => {
                fs.writeFileSync(IMAGEPATH + data.chat.path + FileName,buffer,(e) => {
                    if (e) throw e;
                });
            });

        extras[i] = FileName;
    }
}

return extras;

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)