我尝试按照一些 ActionCable 教程通过 ActiveStorage 创建图像记录将数据从客户端传递到服务器端,但它不起作用。
这是我的代码:来自客户端的代码确实传递到服务器端,但我无法通过 ActiveStorage 创建新图像。请帮我解决它并告诉我它为什么会发生。谢谢。
我已经将 pass 图像测试为 base64/blob(我真的不知道)
Room_channel.rb
def image(check)
post = Post.create title: 'testxcxcx'
post.images.attach check['image']
end
房间.咖啡
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:我上面的代码没有考虑缩进。它确实在我的机器上工作。