Upload video with Jquey Ajax | Community
Skip to main content
Answered

Upload video with Jquey Ajax


driaux

Hi with the APi, how to send the video to the question, I have the response : “The uploaded file is incorrect format ..” 

this the test , i have mal all test with ReadAsDataUrl for example or othe rmais si not working 

 

thanks for you help 

function uploadVideo(questionId)
{
    $.ajax({
        url: rootURL+'urlforpresign',
        method: 'post',
        data: {
            'questionid': questionId
        },
        success: function(json) {
            if (json.code == 0) {

            } else {
                var presignedUrl = json.presignedUrl;
                var file = $('#file_'+questionId)[0].files[0];
                var fileName = file.name;
                var reader = new FileReader();
                reader.onload = function (event) {
                   $.ajax({
                    url: presignedUrl,
                    method: 'PUT',
                    data: {
                        file: fileName,
                        file_data: event.target.result,
                        file_type: 'video/mp4'
                    },
                    timeout: 0,
                    beforeSend: function(request) {
                        request.setRequestHeader("Content-Type", "video/webm;codecs=vp8,opus");
                    },
                    headers: {
                        "Content-Type": "video/webm;codecs=vp8,opus"
                    },
                    ContentType: "video/webm;codecs=vp8,opus",
                    success: function(data) {
                        console.log('success', data)
                    },
                    done: function (response) {
                        console.log(response)
                    },
                    error: function(xhr, ajaxOptions, thrownError) {
                        if (xhr.status == 0 && thrownError == '') {
                            return;
                        }
                        console.log(thrownError);
                        //notifyError("{/literal}{t}Erreur pendant l'enregistrement{/t}{literal}");
                    }
                })
                }
                reader.readAsBinaryString(file);
            }
        }
    });
}

 

Best answer by driaux

   var presignedUrl = json.presignedUrl;
    var file = $('#file_'+questionId)[0].files[0];

    var settings = {
         "url": presignedUrl,
        "method": "PUT",
        "timeout": 0,
        "headers": {
           "Content-Type": "video/webm;codecs=vp8,opus"
         },
        "data": file,
        "processData": false
    };

$.ajax(settings).done(function (response) {
  console.log(response);
});

hi you are make the fix ?  this code is working just now (this code not working yesteday )  🙂🙂 :) 

View original

6 replies

driaux
  • Author
  • Explorer
  • 3 replies
  • April 1, 2022

hi no return ? you have no solution for me please ? :) 


Grace
Community Team
Forum|alt.badge.img+5
  • Community Advocate
  • 2668 replies
  • April 1, 2022

Hi @driaux thanks for your question and sorry we haven’t got an answer for you yet! 

I believe some of the team are looking into this, so hopefully we’ll have some insights for you today! 🙏


Grace
Community Team
Forum|alt.badge.img+5
  • Community Advocate
  • 2668 replies
  • April 1, 2022

Hey @driaux we’ve done some testing and seem to be getting the same errors so going to do some troubleshooting and see what’s happening here


driaux
  • Author
  • Explorer
  • 3 replies
  • Answer
  • April 1, 2022
   var presignedUrl = json.presignedUrl;
    var file = $('#file_'+questionId)[0].files[0];

    var settings = {
         "url": presignedUrl,
        "method": "PUT",
        "timeout": 0,
        "headers": {
           "Content-Type": "video/webm;codecs=vp8,opus"
         },
        "data": file,
        "processData": false
    };

$.ajax(settings).done(function (response) {
  console.log(response);
});

hi you are make the fix ?  this code is working just now (this code not working yesteday )  🙂🙂 :) 


Grace
Community Team
Forum|alt.badge.img+5
  • Community Advocate
  • 2668 replies
  • April 1, 2022

That’s great news @driaux ! Hopefully it continues to work, will update you on anything the team finds in the meantime!


Gabi Amaral
Ex–Typefomer
Forum|alt.badge.img+5
  • Ex–Typefomer
  • 1777 replies
  • April 4, 2022

Happy your code is working now, @driaux! Don't forget to share your videoask with us so we can take a look and give some feedback! 😉

Wishing you a great week! 


Reply