我正在使用youtube api从我的网页上传视频。
这是我的html表单:
<form method="post" id="video_form" enctype="multipart/form-data" action="http://uploads.gdata.youtube.com/action/FormDataUpload/key=http://localhost:3000/en/id=4fc3af871d41c808f3000249" accept-charset="UTF-8"><div style="margin:0;padding:0;display:inline"><input type="hidden" value="✓" name="utf8"><input type="hidden" value="key=" name="authenticity_token"></div>
<label for="Select_a_video">Select a video</label>
<input type="file" name="yt_video_id" id="yt_video_id">
<div class="actions">
<input type="submit" value="Upload video" name="commit" id="submit_video_button" data-disable-with="Upload video" class="btn-large btn-primary">
</div>
</form>
我使用twitter bootstrap进行设计,我有这个进度条:
$(document).ready(function(){
var progress = setInterval(function() {
var $bar = $('.bar');
if ($bar.width()==400) {
clearInterval(progress);
$('.progress').removeClass('active');
} else {
$bar.width($bar.width()+40);
}
$bar.text($bar.width()/4 + "%");
}, 800);
});
您可以在http://jsfiddle.net/xXM2z/68/
中看到示例我的问题是进度条(进度)与发送文件的字节或兆字节不同步。
我希望进度条与发送文件的字节或兆字节同步并正确显示进度...
我该怎么做?
非常感谢
答案 0 :(得分:1)
AFAIK,除非您使用AJAX / XHR上传文件,否则不能这样做。如果您将其留在浏览器中,您将只知道整个文件的上传时间。
以下是XHR示例:
http://hacks.mozilla.org/2009/06/xhr-progress-and-richer-file-uploading-feedback/
但是,我不知道YouTube API是否支持此功能。