S
S
Stanislav2017-04-17 21:17:12
Node.js
Stanislav, 2017-04-17 21:17:12

How to upload a file correctly?

I don’t understand what the problem is when uploading a file, in particular, the problem with mobile devices.
There is a form on the site, using js I send the document id to search for the file and follow up with it.
In the handler, I reduce and crop the image

function resize(s, w) {
    gm(
        path.image // путь до изображения
    )
        .resize(s.w, s.h, '^')
        .gravity('Center')
        .crop(s.w, s.h)
        .quality(90)
        .noProfile()
        .toBuffer(function (e, buffer) {
            return c(e, buffer);
        });
}

After processing, I give as follows
res.statusCode = 200;
res.setHeader('content-type', 'image/jpeg');
res.setHeader('Content-Disposition', 'attachment; filename=' + data.get.image); // название картинки вместе с расширением
res.end(buffer);

The file is being downloaded from the PC and everything is fine, but from the mobile phone "The file is without a name. The file could not be loaded."
I understand the problem with the headers? What's wrong with them?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dummyman, 2017-04-18
@ms-dred

You didn't specify the buffer size in the response headers and I would also write the content-type from large beeches. Although express may fix itself

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question