【发布时间】:2012-08-19 03:11:18
【问题描述】:
我正在使用标准 Zend Youtube 库将视频上传到 Youtube。它运行良好,但我需要上传器在不刷新的情况下运行。
我试图实现它,但我总是得到: 302 Found 来自 youtube 上传网址的响应, 400 Missing token已发送到我的脚本
创建上传器的方法
public static function showUploadForm($presenter, $id, $name, $comment) {
$yt = self::getYt(); // these are the account settings
// create a new VideoEntry object
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$myVideoEntry->setVideoTitle($name);
$myVideoEntry->setVideoDescription($comment);
// The category must be a valid YouTube category!
$myVideoEntry->setVideoCategory('People');
// Set keywords. Please note that this must be a comma-separated string
// and that individual keywords cannot contain whitespace
$myVideoEntry->SetVideoTags('hockey');
$tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
$tokenArray = $yt->getFormUploadToken($myVideoEntry, $tokenHandlerUrl);
$tokenValue = $tokenArray['token'];
$postUrl = $tokenArray['url'];
// place to redirect user after upload
$nextUrl = $presenter->link('//User:videoUploaded', array('id' => $id)); //framework action
// build the form
$form = '<form id="youtubeUploader" class="ajaxSetVideoData" action="' . $postUrl . '?nexturl=' . $nextUrl .
'" method="post" enctype="multipart/form-data">' .
'<input id="file" name="file" type="file" />' .
'<input name="submit" type="submit" value="send" />' .
'<input name="token" type="hidden" value="' . $tokenValue . '"/>'.
'</form>' .
'<br />';
return $form;
}
非常感谢。
编辑:我发现只有输入的“令牌”作为参数发送到 youtube URL。
EDIT2:AJAX 和文件上传存在问题。有了这个插件,它就可以工作了: http://malsup.com/jquery/form/#code-samples
但现在仍然在两个脚本中找到 302,但 URL 中的“状态”是 200(第二行),这没关系 - 视频也上传了。
【问题讨论】:
-
嗯,这是一个...它只是 zend youtube 上传器
-
http 302,是一个重定向。猜猜这与您将数据发布到另一个域的事实有关,这就是为什么警告 XSS 可能是“红色”的原因?抱歉我迟到的回答:)
-
没问题 :) 我浏览了网页,发现最好的办法是改用 IFRAME。
标签: jquery ajax file-upload youtube youtube-api