diff options
author | Aleksey Veresov <aleksey@veresov.pro> | 2019-11-19 19:57:16 +0300 |
---|---|---|
committer | Aleksey Veresov <aleksey@veresov.pro> | 2019-11-19 19:57:16 +0300 |
commit | 0f6943feff48e92b071726abcf83070d8a529a41 (patch) | |
tree | 6e8f89d06f85b66083a8efa00d137efaca2941fa | |
parent | 03c27c8542d23a5e4072f0c080c396ce608c1d50 (diff) | |
download | magi-0f6943feff48e92b071726abcf83070d8a529a41.tar magi-0f6943feff48e92b071726abcf83070d8a529a41.tar.xz magi-0f6943feff48e92b071726abcf83070d8a529a41.zip |
.
-rw-r--r-- | examples/upload.c | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/examples/upload.c b/examples/upload.c index 95c7f87..2ef8bc5 100644 --- a/examples/upload.c +++ b/examples/upload.c @@ -11,24 +11,19 @@ void tempfile_callback(struct magi_file * file, int len, void * _) { - static FILE * file = 0; - if (!strcmp(field->name, "data")) { - if (!file) { - remove(field->name); - file = fopen(field->name, "wb"); + if (!strcmp(file->param_name, "data")) { + static FILE * f = 0; + if (!f) { + remove(file->param_name); + f = fopen(file->param_name, "wb"); } if (len) { - fwrite(buffer, 1, len, file); + fwrite(buffer, 1, len, f); } - if (len < magi_parse_multipart_callback_size) { - fclose(file); - file = 0; + if (len < magi_file_callback_portion_max) { + fclose(f); + f = 0; } - } else if (len) { - field->data = realloc(field->data, field->len + len + 1); - memcpy(field->data + field->len, buffer, len); - field->len += len; - field->data[field->len] = 0; } } |