title: Send file thought Actix websocket
body: <p>I'm having a hard time finding documentation or tutorial in order to send a file throught a websocket.
  Here is my JS:</p>
  <pre class="lang-js prettyprint-override"><code>['dragleave', 'drop'].forEach(event_name =&gt;
  document.addEventListener(event_name, function(e) {
    e.preventDefault();
    let files = e.dataTransfer.files;
    var reader = new FileReader();
    for(let i=0;i&lt;files.length; i++) {
      reader.onload = function(event) {
        socket.send(event.target.result);
      };
      reader.readAsArrayBuffer(files[i]);
    }
    }, false));
  </code></pre>
  <p>My rust code is based on the official examples (<a href="https://github.com/actix/examples/tree/master/websockets/websocket" rel="nofollow noreferrer">https://github.com/actix/examples/tree/master/websockets/websocket</a>):</p>
  <pre class="lang-rust prettyprint-override"><code>impl StreamHandler&lt;Result&lt;ws::Message, ws::ProtocolError&gt;&gt; for RatioUpWS {
      fn handle(&amp;mut self, msg: Result&lt;ws::Message, ws::ProtocolError&gt;, ctx: &amp;mut Self::Context,) {
          // process websocket messages
          println!(&quot;WS: {:?}&quot;, msg);
          match msg {
              Ok(ws::Message::Ping(msg)) =&gt; {
                  self.hb = Instant::now();
                  ctx.pong(&amp;msg);
              }
              Ok(ws::Message::Pong(_)) =&gt; {self.hb = Instant::now();}
              Ok(ws::Message::Text(text)) =&gt; {
                  ctx.text(text);
              }
              Ok(ws::Message::Binary(bin)) =&gt; {
                  let mut pos = 0;
                  let mut buffer = File::create(&quot;foo.txt&quot;).unwrap();  // notice the name of the file that will be written
                  while pos &lt; bin.len() {
                      let bytes_written = buffer.write(&amp;bin[pos..]).unwrap();
                      pos += bytes_written
                  };
                  ctx.binary(bin)
              },
              Ok(ws::Message::Close(reason)) =&gt; {
                  ctx.close(reason);
                  ctx.stop();
              }
              _ =&gt; ctx.stop(), //if file&gt;64K, it goes here
          }
      }
  }
  </code></pre>
  <p>It seems to be recognized as a text message and I don't know how to deserialize it.
  <code>actix_web::web::Form&lt;FormDataStruct&gt;</code> don't seems to be appropriate.</p>
  <p>Any idea?</p>