How to upload RecordRTC blob file to Rails paperclip in AJAX

前端 未结 2 1655
生来不讨喜
生来不讨喜 2021-01-03 13:14

On the client side, the user uses RecordRTC to record a short video. When the user presses upload, I will get the video\'s blob data using recorder.getBlo

2条回答
  •  春和景丽
    2021-01-03 13:49

    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
    

提交回复
热议问题