Search code examples
apivimeovideo-upload

How to upload video directly from client browser to Viemeo using jquery?


I have try to upload a video to vimeo account directly from browser using api ,video details are created but file seems to corrupted/upload not happens.This is my sample code.

   var file = $(this).prop("files")[0];
       var formData = new FormData();
      formData.append("file_data", file);
    
                $.ajax({
                    url: "https://api.vimeo.com/me/videos/",
                    type: "post",
                    data: formData,
                    headers: {
                        "Authorization": "Bearer -----", 
                    },
                    processData: false,
                    mimeType: "multipart/form-data",
                    contentType: false,
                  
                }).done(function (response) {
                    
                               // Do something
                         
                       
                    }).complete(function (response) {
                       // Do something
               
                    }).fail(function (e) {
                    // Do something
                });

vimeo video listing shows blank thumbnail enter image description here


Solution

  • Try this piece of code. I have made some changes here:

    var file = $(this).prop("files")[0];
    var formData = new FormData();
    formData.append("file_data", file);
    
    $.ajax("https://api.vimeo.com/me/videos/", {
        type: "POST",
        headers: {
            "Authorization": "Bearer -----", 
        },
        data: formData,
        contentType: "multipart/form-data",     // changed this
        dataType: "json",
    
        crossDomain: true            // for CORS policy error
    }).done((response) => {
        
        // Do something
    
    }).fail((error) => {
        
        // Do something
    
    }).complete(() => {
    
        // Do something
    
    });
    

    I have chaged contentType and removed mimeType. I've also removed un-necessary processData field.