aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/afm-main-plugin/afm-main-plugin.c29
-rw-r--r--plugins/samples/SamplePost.c17
2 files changed, 22 insertions, 24 deletions
diff --git a/plugins/afm-main-plugin/afm-main-plugin.c b/plugins/afm-main-plugin/afm-main-plugin.c
index 12bd9f33..5315da9d 100644
--- a/plugins/afm-main-plugin/afm-main-plugin.c
+++ b/plugins/afm-main-plugin/afm-main-plugin.c
@@ -127,20 +127,23 @@ static struct json_object *call_file__appid(AFB_request *request, AFB_PostItem *
struct json_object *obj;
char *query;
const char *filename = getPostPath(request);
- request->jresp = NULL;
- if (0 >= asprintf(&query, "\"%s\"", filename))
- request->errcode = MHD_HTTP_INTERNAL_SERVER_ERROR;
- else {
- obj = jbus_call_sj_sync(jbus, request->api, query);
- free(query);
- if (obj)
- request->jresp = embed(request, _id_, obj);
- else
- request->errcode = MHD_HTTP_FAILED_DEPENDENCY;
- }
- unlink(filename);
+
+ if (filename != NULL) {
+ request->jresp = NULL;
+ if (0 >= asprintf(&query, "\"%s\"", filename))
+ request->errcode = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ else {
+ obj = jbus_call_sj_sync(jbus, request->api, query);
+ free(query);
+ if (obj)
+ request->jresp = embed(request, _id_, obj);
+ else
+ request->errcode = MHD_HTTP_FAILED_DEPENDENCY;
+ }
+ unlink(filename);
+ }
}
- return getPostFile (request, item, "/tmp");
+ return getPostFile (request, item, "/tmp/upload");
}
static AFB_restapi plug_apis[] =
diff --git a/plugins/samples/SamplePost.c b/plugins/samples/SamplePost.c
index e419be45..88949736 100644
--- a/plugins/samples/SamplePost.c
+++ b/plugins/samples/SamplePost.c
@@ -72,17 +72,12 @@ STATIC json_object* UploadImage (AFB_request *request, AFB_PostItem *item) {
char *destination = "images";
// This is called after PostForm and then after DonePostForm
- if (item == NULL) {
- AFB_PostCtx *postFileCtx = getPostContext(request);
-
- // 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.
- }
+ if (item == NULL && getPostPath (request) != NULL) {
+ // Do something with your newly upload filepath=postFileCtx->path
+ request->errcode = MHD_HTTP_OK;
+ request->jresp = jsonNewMessage(AFB_SUCCESS,"UploadFile Post Image done");
+
+ // Note: should not return here in order getPostedFile to clear Post resources.
}
// upload multi iteration logic is handle by getPostedFile