Upload a video file by chunks

做~自己de王妃 提交于 2019-12-03 03:20:19

I think your problem could simply be the result of this line:

request.addHeader("Content-Range", "bytes%20" + contentRange);

Try and replace "bytes%20" by simply "bytes "

In your output you see the corresponding header has incorrect content:

Headers: {
    Content-Length=15125120,
    Content-Type=video/mp4,
    Content-Range=bytes%200-10485759/15125120     <-- INCORRECT
}

On the topic of Content-Range...

You're right that an example final block of content should have a range like 14680064-15125119/15125120. That's part of the HTTP 1.1 spec.

Here

 String contentRange = Integer.toString(byteNumber + 1);

you start from 1 and not from 0 at the first iteration.

Here

 request.addHeader("Content-Length", contentLength);

you put the entire file content length and not the length of the current chunk.

The vimeo API page says: "The final step is to call vimeo.videos.upload.complete to queue up the video for transcoding. This call will return the video_id, which you can then use in other calls (to set the title, description, privacy, etc.). If you do not call this method, the video will not be processed."

I added this bit of code to the end and got it to work:

    request = new OAuthRequest(Verb.PUT, "http://vimeo.com/api/rest/v2");
    request.addQuerystringParameter("method", "vimeo.videos.upload.complete");
    request.addQuerystringParameter("filename", video.getName());
    request.addQuerystringParameter("ticket_id", ticket);
    service.signRequest(token, request);        

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