How to upload RecordRTC blob file to Rails paperclip in AJAX

若如初见. 提交于 2019-11-30 16:43:35

I handled kind of same problem in one of my project. The situation was the API has to convert a blob data to image file that was being sent by a mobile device. I am assuming the action to be upload in your controller file.

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

In the end, the cause of problem is that the blob file returned from recorder.getBlob() is not an actual blob. Refer to the answer from muaz-khan.

I added the following lines in RecordRTC to get the real blob and do the same AJAX submitted. Everything work now.

         getBlob: function () {
             return blobURL2;
         },
+        getRealBlob: function() {
+            return blobURL;
+        }, 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!