I found a flow created by Nick using Ajax form for uploading files. I have modified it to write to the filesystem and it works great. I want to be able to pass the success or fail from the file write node back to the form popup message. The flow gives me this message which I realized only looks at the template results and not the write node.
In the above case the file write failed due to incorrect file path. I am using a catch node to dump the output to context.
How can I parse the context data and inserted into the a success or fail object within the Ajax call.
See flow below
[{"id":"b8284e52a98d6edf","type":"group","z":"1370cad3dea7d005","name":"Upload File Template","style":{"label":true},"nodes":["1a5eaffe20d55f62","badef399114c7186","53fe6b3b72822a78","39575309ba1a1ebd","446de8c01dc5aa65","3686c1606299e93c","581e9356067885c4","38a4d739d196aa75","073bfdd2b72907ab","1cfed2d982d8b591","d9c54a5756141e3a"],"x":14,"y":19,"w":412,"h":282},{"id":"1a5eaffe20d55f62","type":"http in","z":"1370cad3dea7d005","g":"b8284e52a98d6edf","name":"","url":"/file-upload","method":"post","upload":true,"swaggerDoc":"","x":120,"y":180,"wires":[["53fe6b3b72822a78","badef399114c7186","3686c1606299e93c"]]},{"id":"badef399114c7186","type":"debug","z":"1370cad3dea7d005","g":"b8284e52a98d6edf","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"req.files","targetType":"msg","statusVal":"","statusType":"auto","x":310,"y":180,"wires":[]},{"id":"53fe6b3b72822a78","type":"function","z":"1370cad3dea7d005","g":"b8284e52a98d6edf","name":"","func":"msg.payload = \"OK\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":140,"y":220,"wires":[["39575309ba1a1ebd"]]},{"id":"39575309ba1a1ebd","type":"http response","z":"1370cad3dea7d005","g":"b8284e52a98d6edf","name":"","statusCode":"","headers":{},"x":290,"y":220,"wires":[]},{"id":"446de8c01dc5aa65","type":"file","z":"1370cad3dea7d005","g":"b8284e52a98d6edf","name":"writeFile","filename":"filename","filenameType":"msg","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"setbymsg","x":300,"y":140,"wires":[[]]},{"id":"3686c1606299e93c","type":"function","z":"1370cad3dea7d005","g":"b8284e52a98d6edf","name":"formatFile","func":"msg = { payload: msg.req.files[0].buffer, filename: '/home/pi'+msg.req.files[0].originalname}\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":140,"y":140,"wires":[["446de8c01dc5aa65"]]},{"id":"581e9356067885c4","type":"ui_template","z":"1370cad3dea7d005","g":"b8284e52a98d6edf","group":"c1de91543c517b44","name":"css","order":1,"width":0,"height":0,"format":"<style>\nlabel, input {\ndisplay: block;\ncolor: #808080;\n}\nlabel {\nmargin-bottom: 10px;\n}\n</style>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":150,"y":100,"wires":[[]]},{"id":"38a4d739d196aa75","type":"comment","z":"1370cad3dea7d005","g":"b8284e52a98d6edf","name":"ReadMe","info":"# Simple Input form to load file from node red dashboard to server\n## Flow automatically picks up file name and msg encoding\n## Default upload location is /home/pi \n - Edit formatFile function to change location\n","x":220,"y":60,"wires":[]},{"id":"073bfdd2b72907ab","type":"ui_template","z":"1370cad3dea7d005","g":"b8284e52a98d6edf","group":"c1de91543c517b44","name":"form","order":5,"width":"6","height":"2","format":"<form id=\"myForm\">\n <label>\n <input id=\"myFile\" type=\"file\" name=\"fileToUpload\">\n </label>\n <label>\n <input type=\"submit\" value=\"Upload File\" name=\"submit\">\n </label>\n</form>\n<script>\n $('#myForm').submit(function(e) {\n e.preventDefault();\n var fd = new FormData(); \n fd.append( 'file', $('#myFile')[0].files[0] );\n\n $.ajax({\n url: '/file-upload',\n data: fd,\n processData: false,\n contentType: false,\n type: 'POST',\n success: function(data){\n alert('Ok');\n $(\"#myForm\")[0].reset();\n }\n });\n });\n</script>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":290,"y":100,"wires":[[]]},{"id":"1cfed2d982d8b591","type":"catch","z":"1370cad3dea7d005","g":"b8284e52a98d6edf","name":"","scope":["446de8c01dc5aa65"],"uncaught":false,"x":150,"y":260,"wires":[["d9c54a5756141e3a"]]},{"id":"d9c54a5756141e3a","type":"function","z":"1370cad3dea7d005","g":"b8284e52a98d6edf","name":"function 1","func":"var error = flow.set(\"error\", msg.error)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":260,"wires":[[]]},{"id":"c1de91543c517b44","type":"ui_group","name":"Upload Files","tab":"f5bc4cdce2c30720","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"f5bc4cdce2c30720","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]