-->
Page 1 of 1

Unable to serve image from webserver on ESP8266

PostPosted: Sat Aug 13, 2016 1:00 pm
by ma.ag37
I have an image on the module but I am unable to get it successfully delivered to the connected clients on the webpage.

I use the following code:

if received_request == "smarty_home.jpg " then
print("image request received\n")
file.open("smarty_home.jpg")
print("image_opened\n")

nextline = file.read(1400)
while nextline do
client:send(nextline)
nextline = file.read(1400)
end
file.close()
print ("image_sent\n")

end

But I get only a portion of image at the client on the webpage

Please Help

Re: Unable to serve image from webserver on ESP8266

PostPosted: Sat Aug 13, 2016 1:56 pm
by devsaurus
The client:send() function is asynchronous, i.e. it will return to your Lua code before the payload is actually sent to the client. In worst case data is overwritten in the internal network buffers which yields the results you observed.
You'd need to restructure your code in a way that consecutive chunks are sent from the sent-callback. Refer to http://nodemcu.readthedocs.io/en/latest ... /net/#note