如何使用PHP中基于表单的方法将视频从文件系统直接从浏览器上传到vimeo

问题描述

我查看了vimeo文档中有关如何使用其API的信息。我能够成功调用他们的api,但无法上传视频。我具有上传权限,我需要使用表单方法直接将视频上传到vimeo。我的问题是,如何对“ / me / videos”执行POST请求并获取要在已部署表单中使用的响应参数。下面是我的代码:

<?php
include '../vendor/vimeo/vimeo-api/autoload.php';
include '../vendor/vimeo/vimeo-api/src/Vimeo/Vimeo.php';

//require_once 'VimeoClass.php';

use Vimeo\Vimeo

$clientid=clientid
$clientsecret=clientsecret
$access_token=access_token
//initialize the vimeo library
$lib = new \Vimeo\Vimeo($clientid,$clientsecret);

//set access token
$lib->setToken($access_token);



  

    $method='POST';

$url="/me/videos";

$headers= array('Authorization' =>'bearer'.$access_token,'Content-Type'=>'application/json','Accept'=>'application/vnd.vimeo.*+json;version=3.4');

if(isset($_POST['btnvideo']) && $_SERVER['REQUEST_METHOD']=='POST'){
    try{
    //get video size
    $file_size=filesize(realpath($_FILES['vfile']['tmp_name']));
    //declare params to send to the request
    $params = array('upload' =>['approach'=>'post','size'=>$file_size,'redirect_url'=>'VideoRedirect.php']);
    $respond=$lib->request($url,$params,$method);

谢谢。

解决方法

<form method="POST" id ="vimeo-form" action="upload.upload_link" enctype="multipart/form-data">
    <label for="file">File:</label>
    <input class="form-control" type="file" name="file_data" id="file" data-link=""><br>
    <input class="form-control" type="hidden" name="duration"><br>
    <input  type="submit" name="submit" value="Submit">
</form>

<?php
    require 'vendor/autoload.php';
    use Vimeo\Vimeo;
    $client_id = 'generated in created app in your vimeo account';
    $client_secret = 'generated in created app in your vimeo account';
    $client_token = 'generated in created app in your vimeo account';
    
    $client = new Vimeo($client_id,$client_secret,$client_token);
?>

<script type="text/javascript">
$.ajax({
        type: 'POST',url: 'https://api.vimeo.com/me/videos',upload: {
                approach: "post",},headers: {
             'Authorization': 'bearer ' + 'acces token','Content-Type': 'application/json','Accept': 'application/vnd.vimeo.*+json;version=3.4'
           },success: function(res){
            console.log(res);
        },error: function(err){
            console.log(err);
        }
    });
<script>

尝试使用此AJAX请求。这是基于Vimeo API documentation

的基于表单的方法

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...