Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. <input class="file-upload-button" (change)="changedPhoto($event)" #inputcamera type="file" accept="image/*" capture="camera" />
  2.  
  3. <button ion-button color="primary" (click)="uploadPicture()">
  4. Upload
  5. </button>
  6.  
  7. ionViewDidLoad() {
  8. const element = this.cameraInput.nativeElement as HTMLInputElement;
  9. element.onchange = () => {
  10. const reader = new FileReader();
  11. reader.onload = (r: any) => {
  12. //THIS IS THE ORIGINAL BASE64 STRING AS SNAPPED FROM THE CAMERA
  13. let base64 = r.target.result as string;
  14. //FIXING ORIENTATION USING NPM PLUGIN fix-orientation
  15. fixOrientation(base64, { image: true }, (fixed: string, image: any) => {
  16. //fixed IS THE NEW VERSION FOR DISPLAY PURPOSES
  17. this.img = fixed;
  18. });
  19. };
  20. reader.readAsDataURL(element.files[0]);
  21. };
  22. }
  23.  
  24. changedPhoto(event) {
  25. this.imageSource = event.target.files[0];
  26. }
  27.  
  28. uploadPicture() {
  29. this.publishedProvider.addPWAPicture(data.imageName, this.itemId, this.itemName, this.imageSource, this.userProfile.id).then(() => {
  30. this.imageName = '';
  31. this.imageSource = null;
  32. });
  33.  
  34. addPWAPicture(imageName, ItemId, itemName, imageSource, uploaderId): firebase.Promise<any> {
  35. let TimeStamp = new Date();
  36. this.items.child('/ItemList').child(ItemId)
  37. .child('ImageList').push({
  38. imageName: imageName,
  39. timestamp: TimeStamp
  40. })
  41. .then((newImage) => {
  42. if (imageSource != null) {
  43. firebase.storage().ref('/itemPicture/').child(newImage.key)
  44. .child('imageSource.jpg').putString(imageSource, 'base64', {contentType: 'image/jpeg'})
  45. }
  46. });
  47. }
  48.  
  49. ERROR Error: Uncaught (in promise): [object Object]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement