Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $scope.uploadVideo = function(){
- // Obtaining the selected file. In case of many, the others will be from the position 1 of the array
- var f = document.getElementById("videoInput").files[0];
- console.log("====================>SIZE: "+f.size);
- var name = f.name;
- //Getting the file name and its extension
- }
- //Loading the file and passing the callback as a parameter
- loadFile(f, function(data){
- // The file consist on its name and bytes
- var file={
- name:name,
- data:data
- }
- //Sending the video
- servicioRest.postFile(file)
- .then(function(){
- //Whatever
- })
- .catch(function(err){
- console.log("ERROR");
- alert("ERROR: "+err);
- });
- });
- };
- //---------------------------------------------------- UTILS ----------------------------------------------
- function loadFile(source, callBack){;
- var r = new FileReader();
- //Event that will be triggered when FileReader finish reading the file
- r.onloadend = function(e){
- var data = e.target.result;
- // some chars cannot be sent through http requests. So we encode them in base64 to ensure we send the correct bytes
- data=btoa(data);
- console.log(data.length);
- callBack(data);
- //send you binary data via $http or $resource or do anything else with it
- }
- //Reading the file. When it ends, the event "onloadend", previously declared, will be triggered
- r.readAsBinaryString(source);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement