#include <stdio.h> #include <sys/io.h> #include <stdlib.h> #include <errno.h> #include < string.h> #include <fcntl.h> #include <sys/types.h> #include <sys/socket.h> #include <time.h
> #include <curl/curl.h> #include <sys/stat.h> #include <dirent.h> #include <sys/inotify.h>
static char g_last_name[20]= "Upload_audio.mp3";
int Sendpostfile ();
unsigned long get_file_size ();
unsigned long get_file_size () {unsigned long filesize =-1;
struct stat statbuff;
if (Stat ("/home/user/upload_audio.mp3", &statbuff) < 0) {return filesize;
}else{filesize = statbuff.st_size;
return filesize;
int Sendpostfile () {CURL *curl;
Curlcode Res;
Char filesize[15]={0};
sprintf (FileSize, "%lu", get_file_size);
struct Curl_httppost *formpost=null;
struct Curl_httppost *lastptr=null;
struct Curl_slist *headerlist=null; static const char BUF[] = "Expect:";
Curl_global_init (Curl_global_all); /* Fill in the File upload field */Curl_formadd (&formpost, &lastptr, Curlfo Rm_copyname, "UploadFile", Curlform_file, G_name, Curlform_contenttype, "application/o
Ctet-stream ", curlform_end);
printf ("Curl_formadd filesize\n"); Curl_formadd (&formpost, &lastptr, Curlform_copyname, "filesize", curl
Form_copycontents, FileSize, curlform_end);
printf ("Curl_formadd submit\n"); Curl_formadd (&formpost, &lastptr, Curlform_copyname, "Upfile", Curlfo
Rm_copycontents, "commit", curlform_end);
Uplog ("Curl curl_easy_init\n");
Curl = Curl_easy_init (); /* Initalize custom Header list (stating that expect:100-continue are not wanted * * Headerlist = Curl_slist_append (headerlist, buf);
if (Curl) {Uplog ("Curl true begin post\n");
/* What URL that receives this POST * * curl_easy_setopt (curl, Curlopt_url, post_file_url);
Curl_easy_setopt (Curl, Curlopt_httpheader, headerlist);
Curl_easy_setopt (Curl, Curlopt_httppost, formpost);
Curl_easy_setopt (Curl, Curlopt_infilesize_large, 1613);
/* Perform the request, res'll get the return code */res = curl_easy_perform (curl); /* Check for errors/if (res!= CURLE_OK) {fprintf (stderr, "Curl_easy_perform () failed:%s\n", Curl_easy_strer
Ror (res));
Uplog ("Curl url_easy_perform () failed:%s \ n", Curl_easy_strerror (res));
return-1;
}/* Always cleanup * * Curl_easy_cleanup (curl);
/* Then cleanup the formpost chain * * Curl_formfree (formpost);
/* Free Slist */Curl_slist_free_all (headerlist);
return 0;
} void Main (int argc, char *argv[]) {if (0==sendpostfile ()) {printf ("Sendpostfile success\n"); }else{PrintF ("Sendpostfile failed\n");
}
}