lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
29.22k stars 1.29k forks source link

image upload problem #2323

Closed aramis2345 closed 4 years ago

aramis2345 commented 4 years ago

Here is my code for image resize upload. (nodjs chat program) but I have problem windows10/chrom84 , ie11 and edge brower.(desktop) devtools says "net::ERR_CONTENT_LENGTH_MISMATCH 200 (OK)" images file resize o.k and file saves o.k but in browser shows broken images, so I refresh the browser, then show images. small images file upload are o.k but large images files sometimes have problem (over 1,2 ~10mb) so, I removed line where sharp resizing code. It's all right.

dose anyone have idea?


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;

};

lovell commented 4 years ago

This looks like a networking problem unrelated to sharp. Perhaps try Stack Overflow or similar.