2013-04-30 26 views
6

Tôi đang chụp ảnh (hoặc chọn từ thư viện) sử dụng PhoneGap API sử dụng drictive sau:nội dung tải hình ảnh từ máy ảnh vào một tập tin

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      
       }) 
      }); 
     } 
    }; 
}); 

nào trả lại cho tôi một URI đó trông như thế nào, sử dụng giả lập gợn trên chrome, mà tôi không thể thấy dán URI này.

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

Vấn đề của tôi đang tải URI này

$scope.updateUserProfile = function (user) { 

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

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

    } 

* Lưu ý: I cannot use phonegap filetransfer together with parse.com :

Khi tôi làm điều đó tôi nhận được:

enter image description here

Tôi đang làm cho yêu cầu của tôi như :

tải lênẢnh: chức năng tải lênẢnh (người dùng, gọi lại) { 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' 
       } 
      }) 

Bất kỳ ý tưởng nào về cách tải nội dung của hình ảnh lên tệp mà tôi có thể tải lên Parse.com một cách hạnh phúc?

Cảm ơn!

+0

Kiểm tra này [Lưu trữ chụp ảnh trên thẻ SD] (http://stackoverflow.com/questions/14928202/save-image-in-local-storage-phonegap/16648829#16648829) –

Trả lời

3

Cuối cùng tôi cũng làm việc đó xung quanh, vì mục tiêu cuối cùng của tôi là sử dụng nó với điện thoại, with the info in this post. . Cảm ơn 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

hoạt động tuyệt vời cảm ơn! –

Các vấn đề liên quan