大佬教程收集整理的这篇文章主要介绍了ruby-on-rails – 如何在AJAX中将RecordRTC blob文件上传到Rails回形针,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
首先,我想更改< input type ='file'> blob数据的字段值.事实证明,对于浏览器的安全性,我无法使用javascript更改它.
然后,我尝试使用AJAX:
$("#ajax-submit").on("click",function() { var data = new FormData(); data.append("record",recorder.getBlob(),(new Date()).getTime() + ".webm"); var oReq = new XMLhttprequest(); oReq.open("POST","/records/"); oReq.send(data); oReq.onload = function(oEvent) { if (oReq.status == 200) { console.log("Uploaded"); } else { console.log("Error " + oReq.status + " occurred uploading your file."); } }; });
但是,它不起作用.在日志文件中,我将得到以下,无法处理:
Processing by RecordsController#create as */* Parameters: { "video"=>"data:video/webm;base64,GkXfo0AgQoaBAUL3gQFC8o..." }
如果我正常使用表单提交,我将有如下参数:
Processing by RecordsController#create as HTML Parameters: { "video"=>#<ActionDispatch::http::UploadedFile:0x3b476e0 @original_filename="tesTing.mp4",@content_type="video/mp4",@headers="Content-Disposition: form-data; name=\"record\"; filename=\"tesTing.mp4\"\r\nContent-Type: video/mp4\r\n",@tempfile=#<File:a_path>> }
我怎么能解决这个问题?
非常感谢.
def upload #extract the video data from params video = params[:video] # define the save path for the video. I am using public directory for the moment. save_path = Rails.root.join("public/videos/#{video.original_filename}") # Open and write the file to file system. File.open(save_path,'wb') do |f| f.write params[:video].read end render :nothing => true end
以上是大佬教程为你收集整理的ruby-on-rails – 如何在AJAX中将RecordRTC blob文件上传到Rails回形针全部内容,希望文章能够帮你解决ruby-on-rails – 如何在AJAX中将RecordRTC blob文件上传到Rails回形针所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。