Navalex
Navalex

Reputation: 264

Process huge files with fastify

I'm trying to make a Fastify server which will handle telemetry and log files from an embedded system. This files can get really huge, we are talking about several Go for one file. I have 2 main restrictions:

After some research, I started to check on @fastify/multipart that seemed to be a good starting pont for managing file upload. I managed to handle little files, but when I started to send a file of 1GB, and the server just rejected because of file size.

So, after I tried to use request.parts() to handle the file in chunks of data and send it to a stream:

app.post('/upload', async (request, reply) => {
    const parts = request.parts()
    for await (const part of parts) {
        if (part.type == 'file') {
            console.log('step')
            const writeStream = createWriteStream('./uploads/' + part.filename)
            part.file.pipe(writeStream)
        }
    }

    return { status: 'ok' }
})

But here, the request just seems to get stuck, not even an error.

Noting that my client will probably be in C++ with less soups possible. Do you guys have any suggestion of protocol, library or any hint to solve this issue ?

Thanks!

Upvotes: 0

Views: 763

Answers (0)

Related Questions