I am currently in the process of downloading a video from a server using JavaScript XHR (specifically Angular $http GET with response type 'blob').
My question is, how can I save this downloaded video to a Chrome application's local storage?
As of now, I am utilizing an Angular wrapper for the HTML5 filesystem API. You can find the wrapper at https://github.com/maciel310/angular-filesystem
writeFileInput: function(filename, file, mimeString) {
var def = $q.defer();
var reader = new FileReader();
reader.onload = function(e) {
var buf = e.target.result;
$timeout(function() {
fileSystem.writeArrayBuffer(filename, buf, mimeString).then(function() {
safeResolve(def, "");
}, function(e) {
safeReject(def, e);
});
});
};
reader.readAsArrayBuffer(file);
return def.promise;
}
The above code snippet is used to save files, but it was designed assuming that the file is received from an input. Since I am not getting this file from an input element, the method readAsArrayBuffer()
is not working as expected.
This results in an error message saying:
TypeError: Failed to execute 'readAsArrayBuffer' on 'FileReader': parameter 1 is not of type 'Blob'.