I want to concat some character strings and a jpeg binary file content to make a http post request in C under LINUX. If i use the normal string operation, the binary content in the jpeg will be terminated once it hits 0x00. (for example, if I have my binary file in HEX to be FF D8 FF C0 00 11 08...), after the concat, the binary part will end up with FF D8 FF C0.
Does anyone know how to solve this problem? The language is in C. Thanks
fp = fopen(filename, "rb")
fseek(fp, 0, SEEK_END);
fileLen = ftell(fp);
fseek(fp, 0, SEEK_SET);
buffer = (char *)malloc(fileLen);
fread(buffer, fileLen, 1, fp);
//now buffer has the content of the JPEG image
//next combine both string and binary together to make a http post request
snprintf(poststr, MAXSUB,
"--%s\r\nContent-Disposition: form-data;"
"name=\"datafile\"; filename=\"%s\"\r\nContent-Type: image/jpeg\r\n\r\n"
"%s\r\n"
"--%s\r\n"
"Content-Disposition: form-data; name=\"boxkey\"\r\n\r\n%s\r\n"
"--%s--", boundary, filename, buffer, boundary, key, boundary);