TL;DR — Sick and tired of XML, jQuery, Base64, XHR, MIME, miltipart? Here is clean and simple WebSocket file transfer!
When we started to craft N2O framework we strive to provide latest technologies on the market. Late in 2011 WebSocket protocol was not yet supported on all browsers and we spawned N2O on pure WebSocket stack blindly without knowing the future. Now we are sure it was right decision. We were sick and tired of XML, Base64, jQuery and XHR polling request known as comet. By numerous requests XHR is supported in N2O started from 2.4 but we engage everyone to decline this power-consuming technology.
Microservices vs Ad-hoc protocols
Once we got a project that involved Blu-ray disc file uploading through web browser. N2O was fit this case thanks to binary nature of WebSocket channel. We were pioneers who implemented simple and clean binary file upload, without all this multipart HTTP bullshit. We really engage anybody to deny both HTTP/1 and HTTP/2 profiles and use pure WebSocket channel. It is much easier, code is clean, no headers, no states, no codes, no mimes. You can build your own ad-hoc protocol easily without trying to fit your API language to resource-based REST endpoints architecture. Yes, we really think that all this microservices buzz are exactly just like design patterns: it solves nothing.
Naturally there still some cases REST is useful like existing systems integration; still WebSockets set of utilities lacks some usefull things like curl and wrk; but WebSockets is young technlology and tools like tcpkali arises and more to come.
Usually we encourage to build stateless N2O applications. This allows you easy scaling but sometimes you to really need access to global state, especialy in web frameworks: sessions, cache and other global resources like processes. Starting from N2O version 2.9 provides powerful n2o_async gen_server process under supervision. Currently N2O supports several clasess of async processes: file for file upload workers; async for web pages workers; and other custom clasess for you needs. The cool thing is that n2o_async hides verbose OTP gen_server templates and provides clean proc/2 callback API for any Erlang module. The other cool thing is that n2o_async supports gen_server's call, cast and info functions.
The only mandatory state value you need to hold during file uploading is a file offset that increments after each chunck. However user may want to put some additional metainformation from FTP packet during upload. For that purposes N2O implements File Transfer Protocol as supevised n2o_async backed by gen_server. By implementing N2O info/3 protocol API the FTP initialization is clean and portable:
The async process needs only shifting state's offset and pushing it back to client
The main idea was to create unified client for node.js and web browser. As you may want to use dropzone.js or other file uploader front ends. At the heart of ftp.js is a bert.js packaging as FTP is working only with BERT formatter. We deny using XHR or other transports for file uploading. However by abstracting enc client formatting function we are saving the ability to use any underlying transpots.
The NITRO element will consist of three buttons: one select the file, other two start and stop uploading process. It should use only ftp.js API that can plugged to any upload front-end such as dropzone.js.