- static esp_err_t http_resp_file(httpd_req_t *req)
- //static esp_err_t download_get_handler(httpd_req_t *req) in development examples
- {
- .........
- do {
- /* Read file in chunks into the scratch buffer */
- chunksize = fread(chunk, 1, SCRATCH_BUFSIZE, fd);
- /* Send the buffer contents as HTTP response chunk */
- //--------------------------------------------------------
- // =====> Last pass will send chunksize = 0
- //---------------------------------------------------------
- if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK) {
- fclose(fd);
- ESP_LOGE(TAG, "File sending failed!");
- /* Abort sending file */
- httpd_resp_sendstr_chunk(req, NULL);
- /* Respond with 500 Internal Server Error */
- httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to send file");
- return ESP_FAIL;
- }
- /* Keep looping till the whole file is sent */
- } while (chunksize != 0);
- /* Close file after sending complete */
- fclose(fd);
- ESP_LOGI(TAG, "File sending complete");
- /* Respond with an empty chunk to signal HTTP response completion */
- //---------------------------------------------------------------------------------------
- // chunksize = 0 is also sent in the following line -- causes problems in FF browser
- // comment it out for Firefox.
- //---------------------------------------------------------------------------------------
- httpd_resp_send_chunk(req, NULL, 0);
- return ESP_OK;
- }
Problem sending chunked response in Beta3 -- fileserver.c.
Problem sending chunked response in Beta3 -- fileserver.c.
In Beta3 and ongoing development examples, in "protocols/.../file_server.c", a terminating chunk with chunksize = "0" is sent twice--once in the do-while loop and again in a closing line. This probably doesn't affect IExplorer, but Firefox (latest beta version) doesn't handle it well--frequently losing track of which images to request. This problem is also present in the later development code examples in "download_get_handler" function in fileserver.c.
NOTE: Edited to correct file name from "fileserver.c" to "file_server.c"
Who is online
Users browsing this forum: No registered users and 103 guests