我正在Rails中建立一个类似API的博客,我需要从android和ios应用程序中获取视频,将它们存储在heroku上的pg数据库中,并以他们能够在其上播放的方式将它们提供给客户端客户端设备。
任何人都可以用回形针指导我如何做到这一点吗?请。
此刻,这就是我的CURL请求GET => /posts/1
回归的问题。
/system/posts/videos/000/000/001/original/VID_20160123_201801.mp4?1453620267
但是Android应用程序无法播放它,抛出这样的错误。
uri = https://system/posts/videos/000/000/001/original/VID_20160123_201801.mp4?1453620267
01-24 17:22:51.108 32752-32752/com.user.franklyspeak D/MediaPlayer_Java: Couldn't open file on client side, trying server side
01-24 17:22:51.138 32752-32752/com.user.franklyspeak E/MediaPlayer-JNI: [FXN][ASD]getVideoSurfaceTexture: null surface texture
01-24 17:22:51.399 32752-32763/com.user.franklyspeak E/MediaPlayer: error (1, -1004)
01-24 17:22:51.399 32752-32752/com.user.franklyspeak E/MediaPlayer_Java: Error (1,-1004)
01-24 17:22:51.399 32752-32752/com.user.franklyspeak D/VideoView: Error: 1,-1004
我的控制器代码如下所示
class PostsController < ApplicationController
before_action :set_post, only: [:show, :update, :destroy]
# GET /posts
# GET /posts.json
def index
@posts = Post.all
render json: @posts
end
# GET /posts/1
# GET /posts/1.json
def show
p = @post.video.url
render json: @post.video.url
# render json: @post
end
# POST /posts
# POST /posts.json
def create
@post = Post.new(post_params)
if @post.save
render json: @post, status: :created, location: @post
else
render json: @post.errors, status: :unprocessable_entity
end
end
# PATCH/PUT /posts/1
# PATCH/PUT /posts/1.json
def update
@post = Post.find(params[:id])
if @post.update(post_params)
head :no_content
else
render json: @post.errors, status: :unprocessable_entity
end
end
# DELETE /posts/1
# DELETE /posts/1.json
def destroy
@post.destroy
head :no_content
end
private
def set_post
@post = Post.find(params[:id])
end
def post_params
params.require(:post).permit(:title, :video)
end
end
我的模特看起来像这样。
class Post < ActiveRecord::Base
has_attached_file :video
do_not_validate_attachment_file_type :video
# validates_attachment_content_type :video, content_type: /\Avideo\/.*\Z/
end