Answered

Upload video with Jquey Ajax

  • 31 March 2022
  • 6 replies
  • 738 views

Userlevel 1

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);
}
}
});
}

 

icon

Best answer by driaux 1 April 2022, 17:03

View original

6 replies

Userlevel 1

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

Userlevel 7
Badge +5

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! 🙏

Userlevel 7
Badge +5

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

Userlevel 1
   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 )  🙂🙂 :) 

Userlevel 7
Badge +5

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

Userlevel 7
Badge +5

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