当我将图像发送到Firebase存储时,它会继续加载并且不会显示任何内容 并且所有图像大小相同" 15 b"。它给我空图像,当我尝试打开下载URL时,它什么都没有显示:
HTML
<ion-content>
<button class="button" ng-click="selImages()">add</button>
</ion-content>
AngularJS
var images = [];
var path = [];
var finimg = [];
var imageblob = [];
var downloadURL = [];
$scope.selImages = function() {
var options = {
maximumImagesCount: 2, // only pick one image
width: 800,
height: 800,
quality: 80
};
$cordovaImagePicker.getPictures(options)
.then(function(results) {
for (var i = 0; i < results.length; i++) {
console.log('Image URI: ' + results[i]);
images.push(results[i].replace(/^.*[\\\/]/, ''));
if ($ionicPlatform.is("android")) {
path.push(cordova.file.cacheDirectory);
} else {
path.push(cordova.file.tempDirectory);
}
finimg.push($cordovaFile.readAsArrayBuffer(path[i], images[i]));
imageblob.push(new Blob([finimg[i]], { type: "image/jpeg" }));
var storageRef = firebase.storage().ref();
var uploadTask = storageRef.child('images/' + images[i]).put(imageblob[i]);
// Register three observers:
// 1. 'state_changed' observer, called any time the state changes
// 2. Error observer, called on failure
// 3. Completion observer, called on successful completion
uploadTask.on('state_changed', function(snapshot){
// Observe state change events such as progress, pause, and resume
// Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
console.log('Upload is ' + progress + '% done');
switch (snapshot.state) {
case firebase.storage.TaskState.PAUSED: // or 'paused'
console.log('Upload is paused');
break;
case firebase.storage.TaskState.RUNNING: // or 'running'
console.log('Upload is running');
break;
}
}, function(error) {
// Handle unsuccessful uploadsx
alert("not goood")
}, function() {
alert("Saved Successfully!!")
// Handle successful uploads on complete
// For instance, get the download URL: https://firebasestorage.googleapis.com/...
$scope.downloadURL.push(uploadTask.snapshot.downloadURL);
});
}
}
);
}