Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.create((observer: Observer) => {
const cameraOptions: CameraOptions = {
quality: 50,
destinationType: options && options.returnBase64 ? Camera.DestinationType.DATA_URL : Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.CAMERA,
encodingType: Camera.EncodingType.JPEG,
correctOrientation: true,
// saveToPhotoAlbum: false,
};
this.setOptions(cameraOptions, options);
Camera.getPicture(cameraOptions)
.then((imageData) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64:
// let base64Image = 'data:image/jpeg;base64,' + imageData;
// console.debug('imageData', imageData);
doGetPicture() {
// TODO:
// get picture from camera
console.log(Device)
let imageSource = (Device.isVirtual ? Camera.PictureSourceType.PHOTOLIBRARY : Camera.PictureSourceType.CAMERA);
Camera.getPicture({
destinationType: Camera.DestinationType.FILE_URI,
sourceType: imageSource,
targetHeight: 640,
correctOrientation: true
}).then((_imagePath) => {
alert('got image path ' + _imagePath);
// convert picture to blob
return this.makeFileIntoBlob(_imagePath);
}).then((_imageBlob) => {
alert('got image blob ' + _imageBlob);
// upload the blob
return this.uploadToFirebase(_imageBlob);
}).then((_uploadSnapshot: any) => {
doTakePicture() {
Camera.getPicture({
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
targetWidth: 640,
correctOrientation: true
}).then((imageData) => {
// imageData is a file path
this.doImageResize(imageData, (_data) => {
this.ngZone.run(() => {
this.currentImage = _data
this.images['thumb'] = _data
})
}, 640)
// get the path correct for android devices
if (this.platform.is("android")) {
imageData = "file://" + imageData
}
doGetPicture() {
// TODO:
// get picture from camera
Camera.getPicture({
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.CAMERA,
targetHeight: 640,
correctOrientation: true
}).then((_imagePath) => {
alert('got image path ' + _imagePath);
// convert picture to blob
return this.makeFileIntoBlob(_imagePath);
}).then((_imageBlob) => {
alert('got image blob ' + _imageBlob);
// upload the blob
return this.uploadToFirebase(_imageBlob);
}).then((_uploadSnapshot: any) => {
alert('file uploaded successfully ' + _uploadSnapshot.downloadURL);
// store reference to storage in database
return this.saveToDatabaseAssetList(_uploadSnapshot);
photoLibrary(appbuddy) {
if (appbuddy) {
this.appbuddy = true;
}
console.log('appbuddy app-camera.ts', this.appbuddy);
this.options.sourceType = Camera.PictureSourceType.PHOTOLIBRARY;
this.doCamera();
}
return Observable.create((observer) => {
if (this.platform.is('android') && sourceType === Camera.PictureSourceType.PHOTOLIBRARY) {
Camera.getPicture(options).then(imagePath => {
return imagePath;
}).catch(error => {
console.log('Camera GetPicture Error: ', JSON.stringify(error));
observer.error(error);
}).then(value => {
currentName = value.substring(value.lastIndexOf('/') + 1, value.lastIndexOf('?'));
return FilePath.resolveNativePath(value);
}).then(filePath => {
currentPath = filePath.substr(0, filePath.lastIndexOf('/') + 1);
console.log('CurrentName, CurrentPath: ', currentName, currentPath);
return this.convertImageAsBase64(currentPath, currentName);
}).catch(error => {
console.log('FilePath Resolve Android Native Path Error: ', JSON.stringify(error));
observer.error(error);
}).then(imageString => {
handler: () => {
self.openCamera(Camera.PictureSourceType.PHOTOLIBRARY);
}
}
handler: () => this.storeImageToSqlite(Camera.PictureSourceType.CAMERA)
},
handler: () => this.storeImageToSqlite(Camera.PictureSourceType.PHOTOLIBRARY)
},
handler: () => {
self.openCamera(Camera.PictureSourceType.CAMERA);
}
},