[En-Nut-Discussion] tap stream of Request
Ole Reinhardt
ole.reinhardt at embedded-it.de
Wed May 4 17:34:07 CEST 2011
Hi Werner,
> i've already told that i'd like to copy files via POST on my MMC Card.
> Actualy I can copy a small file from my webinterface to my card. At the
> try to rebuild my webserver to read in chunk by chunk I've found out
> that the whole requeststream from the Website is completely loaded into
> "stream". And now the questions:
>
> - what is the structure of Structure "FILE" (Type of stream) and how can
> i use it?
You know the standard C library functions fread() / fwrite()?
See
http://www.ethernut.de/api/group__xg_crt_stdio.html#gad243ccb70c35ac793c8a0e9614a1725d
for the API.
> - how can I read in the stream chunk by chuck to copy them to the MMC
> Card?
Just open your file on the MMC card with fopen() and try the following
code:
#define BUFFERSIZE 128
void StreamCopy(FILE * istream, FILE * ostream)
{
int cnt;
char *buff;
buff = malloc(BUFFERSIZE);
for(;;) {
if ((cnt = fread(buff, 1, BUFFERSIZE, istream)) <= 0)
break;
if ((cnt = fwrite(buff, 1, cnt, ostream)) <= 0)
break;
if (fflush(ostream))
break;
}
*cop = 0;
free(buff);
}
But you still have to find the beginning and the end of your file in the
multipart transfer. So perhaps you want to add some data parsing...
> - is there a limit of the transmission from the website to the board
> except by the size of ram?
No, ram is no limit, if you directly write the data to the mmc card as
you just alloc 128 bytes of ram and read the incomming file chunk by
chunk (each 128 bytes)
Bye,
Ole
PS: This is realy basic C programming. You should get somewhat familiar
with the standard C library and stdio functionalities.
--
Thermotemp GmbH, Embedded-IT
Embedded Hard-/ Software and Open Source Development,
Integration and Consulting
http://www.embedded-it.de
Geschäftsstelle Siegen - Steinstraße 67 - D-57072 Siegen -
tel +49 (0)271 5513597, +49 (0)271-73681 - fax +49 (0)271 736 97
Hauptsitz - Hademarscher Weg 7 - 13503 Berlin
Tel +49 (0)30 4315205 - Fax +49 (0)30 43665002
Geschäftsführer: Jörg Friedrichs, Ole Reinhardt
Handelsregister Berlin Charlottenburg HRB 45978 UstID DE 156329280
More information about the En-Nut-Discussion
mailing list