【发布时间】:2015-07-16 21:28:08
【问题描述】:
我一直在尝试通过 ruby 将 MP4 视频上传到 vimeo。起初我以为我会尝试使用 ruby gem,但看着它使用现在已弃用的 vimeo API。我已经能够通过我自己制作的表格上传,但完全使用代码似乎还没有工作。
我有以下代码要通过流 API 上传(它主要基于 vimeo python 库):
auth = "Bearer #{ACCESS_TOKEN}"
resp = HTTParty.post "https://api.vimeo.com/me/videos", headers: { "Authorization" => auth, "Accept" => "application/vnd.vimeo.*+json;version=3.2" }, body: { type: "streaming"}
ticket = JSON.parse(resp.body)
target = ticket["upload_link"]
size = File.size("movie.mp4")
last_byte = 0
File.open("movie.mp4") do |f|
while last_byte < size do
resp = HTTParty.put target, headers: { "Authorization" => auth, "Content-Length" => size.to_s, "Content-Range" => "bytes: #{last_byte}-#{size}/#{size}" }, body: { data: a }
progress_resp = HTTParty.put target, headers: { "Content-Range" => 'bytes */*', "Authorization" => auth }
last_byte = progress_resp.headers["range"].split("-").last.to_i
puts last_byte
end
end
resp = HTTParty.delete "https://api.vimeo.com#{ticket["complete_uri"]}", headers: { "Authorization" => auth }
对于最后一行,resp 输出以下错误:
"{\"error\":\"Your video file is not valid. Either you have uploaded an invalid file format, or your upload is incomplete. Make sure you verify your upload before marking it as complete.\"}"
还有 last_byte 输出:28518622 在一次循环后大于实际文件大小 (11458105)。
【问题讨论】: