Pages

Sunday 27 April 2014

API for sending Video and Validate Format

Video duration validation using paperclip

  • Curl request for sending video
curl --request POST -F "post[file_attributes][media]=@/Users/tarun/Downloads/11.mp4" -F "post[caption]=api hit" -F  "type=Video" -F "pet_id=10" -F "auth_token=tcNkgmEipgezpFcf1fio" "localhost:3000/api/v1/posts.json"

video_path = params[:post][:file_attributes][:media].tempfile.path
video_name = params[:post][:file_attributes][:media].original_filename

Validation:-

def self.validate_video_format(name)
   video_format = File.extname(name)
   formats = [".mov", ".flv", ".MOV", ".mp4", ".MP4", ".3gp", ".webm", ".mkv", ".m4v"]
   if formats.include? video_format
     return true
   else
     return false
   end
 end

No comments:

Post a Comment