Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <input class="file-upload-button" (change)="changedPhoto($event)" #inputcamera type="file" accept="image/*" capture="camera" />
- <button ion-button color="primary" (click)="uploadPicture()">
- Upload
- </button>
- ionViewDidLoad() {
- const element = this.cameraInput.nativeElement as HTMLInputElement;
- element.onchange = () => {
- const reader = new FileReader();
- reader.onload = (r: any) => {
- //THIS IS THE ORIGINAL BASE64 STRING AS SNAPPED FROM THE CAMERA
- let base64 = r.target.result as string;
- //FIXING ORIENTATION USING NPM PLUGIN fix-orientation
- fixOrientation(base64, { image: true }, (fixed: string, image: any) => {
- //fixed IS THE NEW VERSION FOR DISPLAY PURPOSES
- this.img = fixed;
- });
- };
- reader.readAsDataURL(element.files[0]);
- };
- }
- changedPhoto(event) {
- this.imageSource = event.target.files[0];
- }
- uploadPicture() {
- this.publishedProvider.addPWAPicture(data.imageName, this.itemId, this.itemName, this.imageSource, this.userProfile.id).then(() => {
- this.imageName = '';
- this.imageSource = null;
- });
- addPWAPicture(imageName, ItemId, itemName, imageSource, uploaderId): firebase.Promise<any> {
- let TimeStamp = new Date();
- this.items.child('/ItemList').child(ItemId)
- .child('ImageList').push({
- imageName: imageName,
- timestamp: TimeStamp
- })
- .then((newImage) => {
- if (imageSource != null) {
- firebase.storage().ref('/itemPicture/').child(newImage.key)
- .child('imageSource.jpg').putString(imageSource, 'base64', {contentType: 'image/jpeg'})
- }
- });
- }
- ERROR Error: Uncaught (in promise): [object Object]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement