Advertisement
dav4530

Android-phonegap Video upload to drupal

Jan 18th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
  2.  
  3. function gotFS(fileSystem) {
  4.   // The filesystem is associated with the app's origin.
  5.   var part = localStorage.uploadPath;
  6.   var part2 = part.substring(part.indexOf("VID"));
  7.  
  8.   var path = "/mnt/sdcard/DCIM/Camera/"+part2;
  9.   fileSystem.root.getFile(path, null, gotFileEntry, fail);
  10.  
  11.  }
  12.  
  13. function gotFileEntry(fileEntry) {
  14.    
  15.   fileEntry.file(function(file){
  16.  
  17.     localStorage.filename = file.name;
  18.     localStorage.filepath = file.fullPath;
  19.    
  20.       url = "http://192.168.38.122/langator/?q=server"; // Services endpoint
  21.  
  22.       var result;
  23.       var data;  
  24.       var reader = new FileReader();
  25.  
  26.       reader.onloadend = function(evt) {
  27.           console.log("read success");
  28.           result = evt.target.result;
  29.  
  30.       };
  31.       reader.readAsDataURL(file);
  32.  
  33.         data = {
  34.             "file" : result,
  35.             "filename" : localStorage.filename,
  36.            }
  37.        
  38.     drupalPostFile(data, url, postwith);
  39.    
  40.   }, function(error){
  41.     alert("Error is "+error);
  42.    
  43.   });
  44.  }
  45.  
  46.  function fail(error) {
  47.  
  48.    alert("An error has occurred: Code = " + error.code);
  49.  }
  50.  
  51.  function drupalPostFile(d, url, successFunction) {
  52.    var url = url + '/file.json';
  53.    $.ajax({
  54.      url : url,
  55.      type : "POST",
  56.      data : d,
  57.      
  58.      contentType: false,
  59.      processData: false,
  60.      success : function(data) {
  61.        
  62.          alert("Success file upload ");
  63.  
  64.        successFunction(data);
  65.      
  66.      },
  67.      error : function(e) {
  68.        
  69.        alert("Error file upload " + e.status);      
  70.      }
  71.    });
  72.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement