Reputation: 93
I'm searching for the best way to force download of a generated video (~50mb) from client-side with javascript and no access to the server. i'm aware of this similar question (which solution in my case don't work because of the cors policy). So my question refers to aws s3. Is there a simple way (maybe using the aws sdk with webbrowsers) to force downloads?
Or would it be simpler to use the buffer object from the Plyr videoplayer (yes there is also a player which plays this video) to make a downloadable mp4 out of it?
respectively a solution like this?
var req = new XMLHttpRequest();
var videourl = "https://shotstack-api-stage-output.s3-ap-southeast-2.amazonaws.com/t63shcspnh/c7a6163b-686a-4cf0-837f-94a922a10a6c.mp4"
req.open('GET', videourl, true);
req.responseType = 'blob';
req.onload = function() {
// Onload is triggered even on 404
// so we need to check the status code
if (this.status === 200) {
var videoBlob = this.response;
var vid = URL.createObjectURL(videoBlob); // IE10+
// Video is now downloaded
// and now save it
const a = document.createElement('a');
a.href = vid;
a.download = filename;
document.body.appendChild(a);
a.click();
}
}
req.onerror = function() {
// Error
}
req.send();
Upvotes: 1
Views: 108