Reading in large files from spiffs
Posted: Wed Sep 18, 2019 3:39 pm
Hi Guys.
I'm trying to read in a large file from spiffs so i can use it as an output to a webserver.
My code seems to work fine on small files ie anything under approx 1000 bytes
but soon as its over my esp32 panics and im trying to work out what ive missed out or not thought about.
when i run this on a file this is the output i get
I'm trying to read in a large file from spiffs so i can use it as an output to a webserver.
My code seems to work fine on small files ie anything under approx 1000 bytes
but soon as its over my esp32 panics and im trying to work out what ive missed out or not thought about.
Code: Select all
static void readTest(char *fname)
{
FILE* file;
char *file_buf;
size_t bytes_read;
unsigned int file_size = 0;
char cont_len[8];
file = fopen(fname, "r");
if(file != NULL) {
fseek(file, 0, SEEK_END);
file_size = ftell(file);
fseek(file, 0, SEEK_SET);
sprintf(cont_len, "%d", file_size);
printf("File size: %d Bytes\n", file_size);
printf("content-length %s\n", cont_len);
file_buf = (char *)malloc(file_size);
if (file_buf == NULL) {
printf("Failed to allocate memory\n");
}
bytes_read = fread(file_buf, file_size, 1, file);
std::string l_output(file_buf,file_size);
l_output = mspUtils::trim(l_output);
printf("output:\n");
printf("%s\n", l_output.c_str());
printf("#####\n");
fclose(file);
} else {
printf("Failed to open file for sending\n");
}
}
any help or point into the right direction would be great#########################
test reading js file
#########################
File size: 43569 Bytes
content-length 43569
abort() was called at PC 0x40166df7 on core 0
ELF file SHA256: 0000000000000000000000000000000000000000000000000000000000000000
Backtrace: 0x40088c20:0x3ffb1dd0 0x40088e6d:0x3ffb1df0 0x40166df7:0x3ffb1e10 0x40166e3e:0x3ffb1e30 0x40167677:0x3ffb1e50 0x4016789a:0x3ffb1e70 0x40173ccd:0x3ffb1e90 0x400d29ef:0x3ffb1eb0 0x400d3a11:0x3ffb1ee0 0x400d42c6:0x3ffb1f20 0x4010679b:0x3ffb2400 0x4008da39:0x3ffb2420
Rebooting...
ets Jun 8 2016 00:22:57