问题
I am using cordovaCamera plugin to get file url in my ionic app.
I wish to put this file on firebase storage not as base64 .
Here is my code for reference
$cordovaCamera.getPicture(options)
.then(function(imageData) {
var pthref = firebase.storage().ref().child("a/b");
pthref.put(WHAAT SHOULD GO HERE).then(function(snapshot) {
alert('file uploaded!');
},
function(a)
{
alert("error"+JSON.stringify(a))});
},
function(err) {
alert("Camera Error")
});
回答1:
In order to make it works you will need to use destinationType: Camera.DestinationType.FILE_URI
to get the URL of the image.
Then, you can get the Blob from this image with cordova-plugin-file
(don't forget to add it) and send it to Firebase.
This code could have syntax mistake I am converting it from Ionic 2 code.
var options = {
destinationType: Camera.DestinationType.FILE_URI
};
$cordovaCamera.getPicture(options)
.then(function (fileUrl) {
window.resolveLocalFileSystemURL(fileUrl, (fileEntry) => {
fileEntry.file((file) => {
let reader = new FileReader();
reader.onloadend = function () {
let imgBlob = new Blob([ this.result ], { type: "image/jpeg" } );
// Send file to firebase here
var pthref = firebase.storage().ref().child("a/b");
pthref.put(imgBlob);
};
reader.onerror = (error) => {
console.error(error);
};
reader.readAsArrayBuffer(file);
}, (error) => {
console.error(error);
});
})
},
function (err) {
alert("Camera Error")
});
来源:https://stackoverflow.com/questions/46787197/how-to-put-file-on-firebase-storage-in-ionic