curl-library
How to POST file with filename?
Date: Thu, 15 Oct 2009 16:55:52 -0400
Hi,
I am trying to use libcurl to post a file and what I want to do is
that I want to give filename and file content to the server so the
server can save file according to the name I give.
For instance, if I say "location=abc.txt&data=abc", the server will
create abc.txt file and write abc to the abc.txt file.
I can do the above fairly easily by following examples but what I
really want to do is that I want to mmap file and simple pass it as an
argument to libcurl.
I am just not sure how I can pass mmap file together with "location=abc.txt"
So I wrote the code as follows.
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL,
"https://192.168.1.101/SaveFile/save_file");
// ignore self-signed certificate
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(buf) + fsize);
// Now specify the POST data
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, buf);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, fmap);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
if (res != 0) {
printf("curl_easy_perform failed with %d\n", res);
}
/* always cleanup */
curl_easy_cleanup(curl);
}
Currently server is failing to create a file so I wanted to ask what
went wrong. Please give me some advice to sort out the issue. Or if
you think my approach is not good, please tell me other alternatives.
Thank you.
YEH
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2009-10-15