【问题标题】:Paperclip with ActionCable带 ActionCable 的回形针
【发布时间】:2017-06-10 17:30:03
【问题描述】:

有没有办法通过 ActionCable 传递文件?我正在尝试使用 Paperclip 进行上传。

  <div id="messaging-form" class="form-group">
    <%= f.file_field :msg_image, id:"msg_image" %>
  <%= f.submit "Send", id: "data-send" %>

我的 Javascript 是

return $('#new_message').submit(function(e) {
    e.preventDefault();
    var $this
    $this = $(this);
    msg_image = $this.find('#msg_image');
    App.global_chat.send_message(msg_image.val());
    msg_image.val('');
    return false;
  }
});

//inside my App.cable.subscriptions.create
    send_message: function(msg_image) {
      return this.perform('send_message', {
        msg_image: msg_image
      });
    }


//message_broadcast_job.rb
class MessageBroadcastJob < ApplicationJob
  queue_as :default

  def perform(data)
    message = Message.create!(msg_image: data['msg_image'])
    ActionCable.server.broadcast "conversations_#{message.conversation.id}_channel",
      message: message
  end

end

显然,仅通过 msg_image.val() 传递图像文件路径不是正确的方法。我需要回形针正确保存文件所需的实际数据。

我能找到的关于这方面的最新信息是一年前的,说不可能通过 ActionCable 传递文件。但是,我想知道是否有任何更新,或者是否有人发现了一个好的 hack。

【问题讨论】:

    标签: javascript ruby-on-rails websocket paperclip actioncable


    【解决方案1】:

    我后来发现虽然 Websockets 可以处理文件,但 Rails ActionCable 不能。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-04
      • 1970-01-01
      • 1970-01-01
      • 2011-03-21
      • 2015-06-07
      • 1970-01-01
      相关资源
      最近更新 更多