- // Allocate an application specific handle to this post
- strncpy (filepath, request->config->sessiondir, sizeof(filepath));
- strncat (filepath, "/", sizeof(filepath));
- strncat (filepath, item->filename, sizeof(filepath));
-
- if((appCtx->fd = open(filepath, O_RDWR |O_CREAT, S_IRWXU|S_IRGRP)) < 0) {
- appCtx->jerror= jsonNewMessage(AFB_FAIL,"Fail to Create destination=[%s] error=%s\n", filepath, strerror(errno));
- goto ExitOnError;
- }
- } else {
- // reuse existing application context
- appCtx = (appPostCtx*) postHandle->ctx;
- }
-
- // Check we successfully wrote full buffer
- len = write (appCtx->fd, item->data, item->len);
- if (item->len != len) {
- appCtx->jerror= jsonNewMessage(AFB_FAIL,"Fail to write file [%s] at [%s] error=\n", item->filename, strerror(errno));
- goto ExitOnError;
+ // if postFileCtx == NULL then an error happen [getPostedFile automatically reports errors]
+ if (postFileCtx != NULL) {
+ // Do something with your newly upload filepath=postFileCtx->path
+ request->errcode = MHD_HTTP_OK;
+ request->jresp = jsonNewMessage(AFB_FAIL,"UploadFile Post Image done");
+
+ // Note: should not return here in order getPostedFile to clear Post resources.
+ }