使用 Faye 发送文件

Sending files with Faye

是否可以使用 Faye Ruby 服务器发送文件?

看起来 FormData 只能用于 XHR,因为例如:

var fd = new FormData();
fd.append('file', $('.file')[0].files[0]);

client.publish(channel, { file: fd });

returns 我的 Ruby 应用程序中的空哈希。

使用 FileReader 制作。

var sendMessage = function(file) {
  client.publish(channel, { file: file });
}

var fr = new FileReader();

fr.onload = function(event) {
  sendMessage(event.target.result);
};

fr.readAsDataURL($('.file')[0].files[0]);