Sto tentando di caricare una foto dal dispositivo mobile allo storage BLOB BLU utilizzando Cordova API. Non riesco proprio a farlo funzionare. Qualsiasi idea aiuterà molto.come caricare una foto sullo storage BLOB BLU usando Cordova API?
I dati caricati su BLOB hanno questo aspetto.
inizio ---->
- +++++ org.apache.cordova.formBoundary
Content-Disposition: form-data; name = "file"; filename = "test"
Content-Type: image/jpeg
Content-Length: 46785
....
< --- fine
Il mio codice:
/*Cordova Camera API calls*/
$scope.takePic = function (type) {
if (navigator.camera != undefined) {
if (type == 'PHOTOLIBRARY')
type = Camera.PictureSourceType.PHOTOLIBRARY;
else if (type == 'CAMERA')
type = Camera.PictureSourceType.CAMERA;
var options = {
quality: 45,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: type,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
saveToPhotoAlbum: false
}
navigator.camera.getPicture(onSuccess, onFail, options);
}
}
$scope.message = "Add an image";
var onSuccess = function (DATA_URL) {
$scope.message = "Choose another image";
$scope.postForm.onFileSelect = DATA_URL;
$scope.$apply();
};
var onFail = function (e) {
$scope.picData = null;
$scope.message = "On fail " + e;
};
//$scope.blobSasUrl is url to upload to azure blob storage
var xhr = new XMLHttpRequest();
xhr.onerror = fail;
xhr.onloadend = uploadCompleted;
xhr.open("PUT", $scope.blobSasUrl);
xhr.setRequestHeader('x-ms-blob-type', 'BlockBlob');
xhr.setRequestHeader('x-ms-blob-content-type', 'image/jpeg');
xhr.send($scope.postForm.onFileSelect);
Modifica ---- // Sto utilizzando Camera.DestinationType.DATA_URI. Ho anche provato FILE_URI.
//This is not working (error)
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log(evt.target.result); //nothing happens here
}
reader.readAsDataURL(file); //file is either DATA_URI or FILE_URI
Ho anche provato l'oggetto FileReader ma reader.onloadend non viene mai attivato. Non sei sicuro del perché ... – wil
Non hai menzionato quale errore ottieni – Thraka
Onestamente non ho idea del tuo codice ma questo post potrebbe aiutarti. la mia domanda è stata fatta con l'aiuto di questo post. seguilo [http://blogs.msdn.com/b/writingdata_services/archive/2014/12/15/epic-saga-final-chapter-success-or-how-to-upload-images-to-azure-from -a-Cordova-app.aspx] (http://blogs.msdn.com/b/writingdata_services/archive/2014/12/15/epic-saga-final-chapter-success-or-how-to-upload- image-to-azure-from-a-cordova-app.aspx) –