I’m able to upload photos taken with the Camera plugin to firebase using the two methods below.
This process is not a pain in the ass because I can send a dataUrl to Firebase…
VIDEO on the other hand, I’m so tired of dealing with this shit. I’ve tried doing everything imaginable. What I keep getting when trying readAsDataUrl() is {“code”:5,“message”:“ENCODING_ERR”}
Using ‘file://’ + fullPath gives me
{“code”:13,“message”:“input is not a directory”}
HELP
onTakePhoto()
onTakePhoto() {
this.camera.getPicture({
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
correctOrientation: true
})
.then(
imageData => {
this.imageUrl = 'data:image/jpeg;base64,' + imageData;
this.imageTaken = true;
}
)
.catch(
err => {
console.log(err);
}
);
}
uploadImage()
uploadImage() {
let storageRef = firebase.storage().ref();
// Create a timestamp as filename
const filename = this.idServ.currentReportID;
const imageRef = storageRef.child(`images/${filename}.jpg`);
imageRef.putString(this.imageUrl, firebase.storage.StringFormat.DATA_URL)
.then(res => {
console.log(res);
console.log("uploadImage res");
}).catch(err => {
console.log(err);
console.log("uploadImage err");
})
}
onRecordVideo()
onRecordVideo() {
this.mediaCap.captureVideo(this.videoOptions)
.then(
(data: MediaFile[]) => {
console.log(data);
var i, len;
for (i = 0, len = data.length; i < len; i += 1) {
// this.videoPath = 'file:// ' + data[i].fullPath;
this.videoPath = 'documents://' + data[i].fullPath;
// this.videoPath = data[i].fullPath;
this.videoName = data[i].name;
console.log("here's the videoPath: " + this.videoPath);
console.log("here's the videoName: " + this.videoName);
// this.algorithm();
}
this.videoTaken = true;
},
(err: CaptureError) => {
console.error(err);
}
);
}
uploadVideo()
uploadVideo() {
console.log("inside uploadVideo()");
//FIREBASE EXCLUSIVE STUFF
let storageRef = firebase.storage().ref();
const filename = this.idServ.currentReportID;
const videoRef = storageRef.child(`videos/${filename}.mov`);
// videoRef.put(this.videoPath).then( res => {
// console.log('Uploaded a blob or file!');
// }).catch(err =>{
// console.log(err);
// });
// videoRef.putString(this.videoPath)
// .then(res => {
// console.log(res);
// console.log("uploadVideo res");
// }).catch(err => {
// console.log(err);
// console.log("uploadVideo err");
// })
this.file.readAsDataURL(this.videoPath, this.videoName).then(res => {
console.log("readAsDataURL res");
console.log(res);
this.videoDataUrl = res;
videoRef.putString(this.videoDataUrl, firebase.storage.StringFormat.DATA_URL)
.then(res => {
console.log(res);
console.log("uploadVideo res");
}).catch(err => {
// console.log(err);
console.log("uploadVideo err");
})
}, err => {
console.log(err);
console.log("putString err");
})
}