Vimeo CORS问题 [英] Vimeo CORS Issue

查看:115
本文介绍了Vimeo CORS问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Ajax将视频上传到Vimeo,但是我遇到了Firefox的CORS问题。

I am trying to upload a video to Vimeo via Ajax but I am running into CORS problems with Firefox.

这是我正在使用的代码。只是在发布文件的最后阶段,CORS保护才会阻止上传。

Here is the code I am using. It is only at the last stage of posting the file does CORS protection prevent the upload.

我检查了标头,并正确设置了交叉原点。

I have checked the headers and Cross Origin is set correctly.

$.ajax({
  url:'https://api.vimeo.com/me',
  crossDomain:true,
  headers:{Authorization: 'bearer ',Accept:'application/vnd.vimeo.*+json;version=3.2'},
  error:function(){
          videoError('Couldn\'t get a quota');
  },
  success:function(uploadQuota){
        if(uploadQuota.upload_quota.space.free > 0 && (uploadQuota.upload_quota.quota.sd == true || uploadQuota.upload_quota.quota.hd == true)){

        //Get Upload Ticket
        $.ajax({
          url:'https://api.vimeo.com/me/videos',
          data:{type:'POST'},
          type:'POST',
          dataType:'json',
          crossDomain:true,
          headers:{Authorization: 'bearer ',Accept:'application/vnd.vimeo.*+json;version=3.2'},
          error:function(){
                  videoError('Couldn\'t get a ticket');
          },
          success:function(uploadTicket){
            if(uploadTicket.ticket_id != ''){
                //Upload File
                var videoData = new FormData();
                $.each($('#video_upload')[0].files, function(i, file) {
                        videoData.append('file_data', file);
                });

                $.ajax({
                        url:uploadTicket.upload_link_secure,
                        type:'POST',
                        headers:{Authorization: 'bearer ',Accept:'application/vnd.vimeo.*+json;version=3.2'},
                        data: videoData,

                        cache: false,
                        contentType: 'multipart/form-data',
                        processData: false,
                        crossDomain:true,
                        //dataType:'jsonp',
                        error:function(){
                                videoError('Error uploading video. Please contact FDN with the ticket id:'+uploadTicket.ticket_id);
                        },
                        success:function(uploadData,status){
                                //Copy id to text box
                        }
                    });
            } else {
                    //If none, process error
            }
        }
    });
  } else {
              //If none, process error
      }
  }                                                                                                                                                                                         
});

是否有明显的我错过或可以尝试的东西?

Is there anything obvious that I have missed or can try?

推荐答案

简短回答: Vimeo POST上传不是为客户端JavaScript设计的。 PUT上传系统 100%支持CORS。

Short Answer: Vimeo POST uploads were not designed for client side JavaScript. The PUT upload system has 100% support for CORS.

长答案:

Vimeo POST上传的目的是提供极其便捷的上传体验。我们给您一张表格。您将表单放在页面的html中,用户使用该表单,并且一切都已设置。这不支持进度条。这是不可恢复的。

Vimeo POST uploads were developed to provide an incredibly easy upload experience. We give you a form. You put the form in the html of your page, The user uses the form, and everything is set. This does not support progress bars. This is not resumable.

上传视频时,我们必须执行一些后处理才能使视频可用。当前的POST上传系统通过在上传完成后重定向客户端来自动处理此问题。不幸的是,CORS和重定向存在一些问题(我很难找到详细信息,但如果我没记错的话,规范指出要以错误情况处理某些重定向)。

When uploading videos, we must perform some post-processing before the video will become available. The current POST upload system handles this automatically, by redirecting the client after the upload is complete. Unfortunately there are some problems with CORS and redirects (I'm having trouble finding the details, but if I remember right the spec states to handle certain redirects as an error case).

现在,您必须自己完成上传。我们正在努力改善这一点,但目前您必须在POST响应的位置标头中找到该url。向该URL发出GET请求,您的上传将完成。

Right now you must complete the upload yourself. We are working on improving this, but for the moment you have to find the url in the "location" header of the response from your POST. Make a GET request to this url and your upload will be complete.

Vimeo PUT上传被设计为功能齐全的高级上传系统。它们是可恢复的,流设计轻松支持进度条。您可以查询上传的状态,并根据命令启动和停止所有操作。 100%支持CORS。这将需要使用HTML5文件对象,该对象对9或更低版本的支持有限。

Vimeo PUT uploads were designed as the fully featured advanced upload system. They are resumable, the streaming design easily supports progress bars. You can query the status of the upload, and start and stop everything on command. CORS is 100% supported. This will require use of the HTML5 file object, which has limited support for ie 9 and lower.

现在,有一个非官方的客户端视频上传脚本流式工作流程。您可以在这里找到它: https://github.com/websemantics/vimeo-upload

There is now an unofficial Client side video upload script for the streaming workflow. You can find it here: https://github.com/websemantics/vimeo-upload

这篇关于Vimeo CORS问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆