+// Some file upload sample
+STATIC json_object* clientFileUpload (AFB_request *request) {
+ int fd;
+ json_object *jresp;
+ char filepath[512];
+ char *filename;
+
+ getQueryValue(request, "filename");
+ if (filename == NULL) return (jsonNewMessage(AFB_FAIL, "No Filename provided"));
+
+ // add an error code to respond
+ if (request->post == NULL) {
+ request->errcode=MHD_HTTP_UNAUTHORIZED;
+ return (jsonNewMessage(AFB_FAIL, "Post No Data"));
+ }
+
+ // This is simple test let's write file in config->session->filename
+ strncpy (filepath, request->config->configfile, sizeof(filepath));
+ strncat (filepath, "/", sizeof(filepath));
+ strncat (filepath, "/", sizeof(filepath));
+
+
+ if((fd = open(request->config->configfile, O_RDONLY)) < 0) {
+ return (jsonNewMessage(AFB_FAIL,"Fail to Upload file [%s] at [%s] error=\n", filename, filepath, strerror(errno)));
+ };
+
+ // write file on disk and free fd
+ write (fd, request->post, request->len);
+ close(fd);
+
+ return (jresp);
+}
+