[ad_1]
Difficulty
I’ve a MediaRecorder video of as much as 400 KB that I have to ship to the server.
I would like to have the ability to additionally ship the video when somebody exits the web page.
My code appears type of like this:
window.onpagehide = (e) => {
e.preventDefault();
var blob = new Blob(this.information, {sort: "video/mp4"});
var file = new File([blob], "recording");
var formData = new FormData();
formData.append("recording", file);
axios.put up('/room/ship/recording', formData)
.then(perform (response) {
if(response.information.outcome) {
console.log("electronic mail has been despatched")
} else {
console.log("did not ship electronic mail")
}
})
.catch(({response}) => {
console.log("an error occured throughout electronic mail name");
console.error(response);
})
return null;
}
Nonetheless window.onpagehide would not enable async capabilities so axios.put up is not working in any respect.
Query
What synchronous axios.put up different can I take advantage of for this situation?
What I attempted
navigator.sendBeacon
It appeared fairly promising, nevertheless it has a restrict of 64KB, so I could not depend on it.
fetch
I attempted the next:
fetch('my-site-url', {
technique: 'POST',
physique: formData
});
And bought the next:
Fetch API can't load my-site-url attributable to entry management checks.
However I do not assume it is a CORS associated concern…
[ad_2]
