我尝试将数据从客户端传递到服务器端,按照ActiveStorage的一些ActionCable教程创建映像记录,但它不起作用 .

这是我的代码:来自客户端的代码确实传递到服务器端但我无法通过ActiveStorage创建新映像 . 请帮助我解决它并让我知道它为什么会发生 . 谢谢 .

我测试了传递图像为base64 / blob(我真的不知道)

Room_channel.rb

def image(check)
post = Post.create title: 'testxcxcx'
post.images.attach check['image'] 
end

Room.coffee

image: (message) ->
@perform 'image', image: message


$(document).on 'turbolinks:load', ->


pullfiles = ->
  # love the query selector
    fileInput = document.querySelector('#message-attachment')
    files = fileInput.files

reader = new FileReader()
dataURL = reader.readAsDataURL $('#message-attachment').get(0).files[0]
console.log blod
#App.room.image reader.readAsDataURL  'does not work'
#App.room.image blod                'does not work'
App.room.image document.getElementById('message-attachment').files[0]
console.log document.getElementById('message-attachment').files[0]

reader.addEventListener 'loadend', ->
  console.log 'Here are binary datas !'
  console.log reader.result      
  App.room.image reader.result 'base64 image'

file_name = files[0].name
console.log file_name
file_name2 = $('#message-attachment').get(0).files[0].name
console.log file_name2



 document.querySelector('#message-attachment').onchange = pullfiles

Ps:我上面的代码没有考虑到缩进 . 它在我的机器上工作 .