Ich versuche, ein Foto von Mobilgerät auf Azure Blob Speicher mit Cordova API zu laden. Ich kann es einfach nicht zur Arbeit bringen. Jede Idee wird sehr helfen.Wie lade ich mit cordova api ein Foto in den azure Blobspeicher hoch?
Daten auf Blob hochgeladen sieht so aus.
Start ---->
- +++++ org.apache.cordova.formBoundary
Content-Disposition: form-data; name = "Datei"; filename = "test"
Content-Type: image/jpeg
Content-Length: 46785
....
< --- Ende
Mein Code:
/*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);
Bearbeiten ----- // Ich verwende Camera.DestinationType.DATA_URI. Ich habe auch FILE_URI versucht.
Ich habe auch versucht, FileReader-Objekt, aber reader.onloadend wird nie ausgelöst. Nicht sicher, warum ... – wil
Sie erwähnen nicht, welchen Fehler Sie erhalten – Thraka
Ehrlich gesagt bekomme ich keine Ahnung von Ihrem Code, aber dieser Beitrag könnte Ihnen helfen. Meine Bewerbung wurde mit Hilfe dieses Posts gemacht. folge ihm [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- images-to-azure-from-a-cordova-app.aspx) –