Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. $scope.uploadVideo = function(){
  2.  
  3. // Obtaining the selected file. In case of many, the others will be from the position 1 of the array
  4. var f = document.getElementById("videoInput").files[0];
  5. console.log("====================>SIZE: "+f.size);
  6. var name = f.name;
  7.  
  8. //Getting the file name and its extension
  9.  
  10. }
  11.  
  12. //Loading the file and passing the callback as a parameter
  13. loadFile(f, function(data){
  14. // The file consist on its name and bytes
  15. var file={
  16. name:name,
  17. data:data
  18. }
  19. //Sending the video
  20. servicioRest.postFile(file)
  21. .then(function(){
  22. //Whatever
  23.  
  24. })
  25. .catch(function(err){
  26. console.log("ERROR");
  27. alert("ERROR: "+err);
  28. });
  29. });
  30. };
  31.  
  32. //---------------------------------------------------- UTILS ----------------------------------------------
  33.  
  34. function loadFile(source, callBack){;
  35. var r = new FileReader();
  36.  
  37. //Event that will be triggered when FileReader finish reading the file
  38. r.onloadend = function(e){
  39. var data = e.target.result;
  40. // some chars cannot be sent through http requests. So we encode them in base64 to ensure we send the correct bytes
  41. data=btoa(data);
  42. console.log(data.length);
  43. callBack(data);
  44. //send you binary data via $http or $resource or do anything else with it
  45. }
  46.  
  47. //Reading the file. When it ends, the event "onloadend", previously declared, will be triggered
  48. r.readAsBinaryString(source);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement