2013-04-30 15 views
6

mi prendo una foto (o selezionando dalla libreria) utilizzando PhoneGap API utilizzando il seguente drictive:Carica il contenuto di immagini dalla fotocamera a un file

MyApp.directive('Camera', function() { 
    return { 
     restrict: 'A', 
     require: 'ngModel', 
     link: function(scope, elm, attrs, ctrl) { 
      elm.bind('click', function() { 
       navigator.camera.getPicture(function (imageURI) 
       { 
        scope.$apply(function() { 
         ctrl.$setViewValue(imageURI); 
        }); 
       }, function (err) { 
        ctrl.$setValidity('error', false); 
       }, 
       //Options => http://docs.phonegap.com/en/2.6.0/cordova_camera_camera.md.html#Camera 
       { quality: 50, 
        destinationType:Camera.DestinationType.FILE_URI      
       }) 
      }); 
     } 
    }; 
}); 

Il che mi restituiscono un URI che assomiglia, utilizzando emulatore ondulazione su Chrome, che non vedo incollare questo URI.

blob:http%3A//localhost%3A8080/8e18de30-d049-4ce2-ae88-8500b444581e 

Il mio problema sta caricando questo URI

$scope.updateUserProfile = function (user) { 

     var myPicfile = $http.get(user.myPicture); 

     dataService.uploadPicture . . . some code to update the picture to Parse 

    } 

* Nota: I cannot use phonegap filetransfer together with parse.com :

Quando faccio che ottengo:

enter image description here

sto facendo la mia richiesta come :

uploadPicture: function uploadPicture (utente, callback) { var serverUrl = 'https://api.parse.com/1/files/' + user.Nick;

  $http({ 
       method: 'POST', 
       url: serverUrl, 
       data: user.myPicture, 
       headers: {'X-Parse-Application-Id': PARSE_APP_ID, 
        'X-Parse-REST-API-Key': PARSE_REST_API_KEY, 
        'Content-Type': 'text/plain' 
       } 
      }) 

Qualche idea su come ottenere il contenuto dell'immagine in un file che allora posso tranquillamente caricare Parse.com?

Grazie!

+0

Scegli questa [Memorizzazione Captured Photo su SD Card] (http://stackoverflow.com/questions/14928202/save-image-in-local-storage-phonegap/16648829#16648829) –

risposta

3

Finalmente l'ho risolto, poiché il mio obiettivo finale era quello di usarlo con PhoneGap, with the info in this post. . Grazie mille a Raymond Camden!

function gotPic(data) { 

window.resolveLocalFileSystemURI(data, function(entry) { 

var reader = new FileReader(); 

reader.onloadend = function(evt) { 
    var byteArray = new Uint8Array(evt.target.result); 
    var output = new Array(byteArray.length); 
    var i = 0; 
    var n = output.length; 
    while(i < n) { 
     output[i] = byteArray[i]; 
     i++; 
    }     
    var parseFile = new Parse.File("mypic.jpg", output); 

    parseFile.save().then(function(ob) { 
      navigator.notification.alert("Got it!", null); 
      console.log(JSON.stringify(ob)); 
     }, function(error) { 
      console.log("Error"); 
      console.log(error); 
     }); 

} 

reader.onerror = function(evt) { 
     console.log('read error'); 
     console.log(JSON.stringify(evt)); 
    } 

entry.file(function(s) { 
    reader.readAsArrayBuffer(s); 
}, function(e) { 
    console.log('ee'); 
}); 

}); 
} 
+0

funziona alla grande, grazie! –

Problemi correlati