[Libwebsockets] Libwebsockets Trouble with chunked file transfering

Andy Green andy at warmcat.com
Fri Jun 12 11:13:39 CEST 2020

On 6/12/20 9:43 AM, Serega Dzivickiy wrote:
> Hi! I'm using your library libwebsockets for my project. I wanna send 
> chunked files via HTTP, because I don't know Content-Length in advance. 
> I read about protocol Transfer-Encoding Chunked, but in your library 
> realisation I didn't find a function which can transfer files with 
> Transfer-Encoding chunked. Also I'm trying to transfer files specifying 
> the size in advance, but it didn't work out. I saw in your library a 
> function named lws_serve_http_file, but I cannot use this function 
> because I haven't file, in my task I wanna transfer bytes chunks for 
> example 1024 byte one packet. And the browser must download these chunks 
> and create one file from these chunks. I tried many methods but I 
> didn't  succeed. Below I will attach examples of my code implementation, 

I don't have time to look through user code debugging it.

> could you please review, maybe I"m doing something wrong? Or maybe I 
> don't know some specific function in your library. Thank you for 

You can do chunked manually, just set the transfer-encoding header 
(with, eg,


and WSI_TOKEN_HTTP_TRANSFER_ENCODING) and emit manually chunked data 
along the lines of this example


without there being any "file".


More information about the Libwebsockets mailing list