X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=afb-client%2Fapp%2FBackend%2FRestApis%2FPostMockApi.js;h=022f7741bc45da5f350ffe823e62520c35233f7f;hb=4136c1506e0c894e604ec069339313987a7e05e7;hp=6299f390fa0d414ca89215089762e9cf8b568283;hpb=07eb8e102607da8d6a4c1cd9835e8465c9280161;p=src%2Fapp-framework-demo.git diff --git a/afb-client/app/Backend/RestApis/PostMockApi.js b/afb-client/app/Backend/RestApis/PostMockApi.js index 6299f39..022f774 100644 --- a/afb-client/app/Backend/RestApis/PostMockApi.js +++ b/afb-client/app/Backend/RestApis/PostMockApi.js @@ -14,20 +14,36 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . + * + * References: https://github.com/expressjs/multer */ var fs = require('fs'); var multer = require('multer'); function NewApi(handle, prefix) { - var self=this; - handle.trace (this,1, "Mock PostApi url=%s", prefix +'/ping'); - var upload = multer({ dest: '/tmp/uploads/' }); + var scope=this; // make sure not to loose object context in async callback - handle.app.post(prefix +'/upload', upload.single('avatar'), function (req, res) { - handle.trace (self, 1, "%s/upload file=", prefix, req.file.originalname); - var upload = multer({ dest: '/tmp/uploads/' }); + // defined upload directory and check it's a valid one + var upload = multer({ dest: handle.config.UPLOAD_DIR}); + // WARNING: single('avatar') should match with + handle.app.post(prefix +'/upload-image', upload.single('avatar'), function (req, res) { + handle.trace (scope, 1, "%s/upload file=%s dest=%s/%s", prefix, req.file.originalname, req.file.destination, req.file.filename); + res.send({"jtype": "TEST_message", "status": "success", "info": "done"}); + }); + + // WARNING: single('music') should match with + handle.app.post(prefix +'/upload-music', upload.single('music'), function (req, res) { + + handle.trace (scope, 1, "%s/upload file=%s dest=%s/%s", prefix, req.file.originalname, req.file.destination, req.file.filename); + res.send({"jtype": "TEST_message", "status": "success", "info": "done"}); + }); + + // WARNING: single('appli') should match with + handle.app.post(prefix +'/upload-appli', upload.single('appli'), function (req, res) { + + handle.trace (scope, 1, "%s/upload file=%s dest=%s/%s", prefix, req.file.originalname, req.file.destination, req.file.filename); res.send({"jtype": "TEST_message", "status": "success", "info": "done"}); });