rest-client-c
rest-client-c copied to clipboard
multipart/form-data
Is there a way to send multipart/form-data with this library ? how do we send it ?
what I mean by this is to send file and buffer in a single request using multipart/form-data. Seems like reading the file into a buffer is the only way ? thx.
Not directly. However, you could write your own readfunc_file and insert it here:
https://github.com/emcvipr/rest-client-c/blob/master/lib/rest_client.c#L527
Maybe check and see if the request mime type starts with multipart/form-data and then use the special readfunc. The special readfunc could insert the mime parts, then stream the body, then the mime trailer.
Thank you so much Jason, I will check this out. Appreciate your quick response.
I did some modifications and now I am able to post a multipart request. I wrote my own readfunc which gets invoked when this header is set like how you mentioned. I write the mime parts in the beginning, stream body and then mime trailer in this special function. Since the memory for the ptr used in this function is managed by curl, I had to do another modification. In the RestRequest_set_file_body() function, I set the size of self->request_body->data_size to the file size + the extra MIME parts I add. this way the curl knows how many times to call this special function and the memory is taken care of. Hope this is fine. Thanks once again!!