Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) => {
alert('file uploaded successfully ' + _uploadSnapshot.downloadURL);
// store reference to storage in database
.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);
makePicture(){
// refresh page here
Camera.getPicture({
destinationType: Camera.DestinationType.FILE_URI,
targetWidth: 1000,
targetHeight: 1000
}).then((imageData) => {
// imageData is a base64 encoded string
// console.log(imageData);
// var img64 = "data:image/jpeg;base64," + imageData;
this.postFile(imageData);
}, (err) => {
console.log(err);
});
}
}
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
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
takePhoto() {
Camera.getPicture({
destinationType: Camera.DestinationType.DATA_URL,
targetHeight: 500,
targetWidth: 500,
correctOrientation: true
}).then((imageData) => {
this.photos.push({ src: "data:image/jpeg;base64," + imageData, likes: 0 });
}, (err) => {
console.log(err);
});
}
setOptions(srcType: number) {
let options = {
quality: 50,
targetWidth: 300,
targetHeight: 300,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: srcType,
encondingType: Camera.EncodingType.JPEG,
mediaType: Camera.MediaType.PICTURE,
allowEdit: true,
correctOrientation: true
}
return options;
}
import {Injectable} from '@angular/core';
import {Camera, Transfer, Device} from 'ionic-native';
/*
Generated class for the Menus provider.
See https://angular.io/docs/ts/latest/guide/dependency-injection.html
for more info on providers and Angular 2 DI.
*/
@Injectable()
export class AppCamera {
options: any = {
quality: 30,
destinationType: Camera.DestinationType.FILE_URI,
correctOrientation: true,
targetWidth: 1204,
targetHeight: 1204
};
iframedoc: any;
appbuddy: boolean = false;
constructor() { }
takePicture(appbuddy) {
if(appbuddy) {
this.appbuddy = true;
}
takePicture() {
if (this.base64Image === this.PLACEHOLDER) {
Camera.getPicture({
correctOrientation: true,
targetWidth: 720,
destinationType: Camera.DestinationType.FILE_URI,
}).then((fileData) => {
this.locationLoading = true;
return this.makeBlobFromFile(fileData);
}).then((imageData) => {
return this.rotateImage(imageData);
}).then((rotatedData: Blob) => {
this.image = rotatedData;
const urlCreator = window.URL || (window as any).webkitURL;
this.base64Image = urlCreator.createObjectURL(rotatedData);
this.getGeoCoords().then(coords => this.coords = coords);
});
} else {
this.resetCoords();
this.base64Image = this.PLACEHOLDER;
}
}
openCamera(pictureSourceType: any) {
var self = this;
let options: CameraOptions = {
quality: 95,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: pictureSourceType,
encodingType: Camera.EncodingType.PNG,
targetWidth: 400,
targetHeight: 400,
saveToPhotoAlbum: true,
correctOrientation: true
};
Camera.getPicture(options).then(imageData => {
const b64toBlob = (b64Data, contentType = '', sliceSize = 512) => {
const byteCharacters = atob(b64Data);
const byteArrays = [];
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
const slice = byteCharacters.slice(offset, offset + sliceSize);