Add rough profile picture upload

master
Max 5 years ago
parent cbf74bba4a
commit 01c9948e0c

@ -3,9 +3,10 @@
<!--on small screen--> <!--on small screen-->
<mat-toolbar color="primary" id="toolbar" fxShow="true" fxHide.gt-sm="true"> <mat-toolbar color="primary" id="toolbar" fxShow="true" fxHide.gt-sm="true">
<mat-toolbar-row> <mat-toolbar-row>
<div class="hover-box" matTooltip="upload new picture" *ngIf="ownProfile"> <div class="hover-box" matTooltip="upload new picture" *ngIf="ownProfile" (click)="fileInput.click()">
<img class="profile-picture" src="https://material.angular.io/assets/img/examples/shiba1.jpg"/> <img class="profile-picture" src="https://material.angular.io/assets/img/examples/shiba1.jpg"/>
<mat-icon id="icon">camera_alt</mat-icon> <mat-icon id="icon">camera_alt</mat-icon>
<input #fileInput type="file" (change)="onFileInput($event)" style="display:none;" />
</div> </div>
<div *ngIf="!ownProfile"> <div *ngIf="!ownProfile">
<img class="profile-picture" src="https://material.angular.io/assets/img/examples/shiba1.jpg"/> <img class="profile-picture" src="https://material.angular.io/assets/img/examples/shiba1.jpg"/>

@ -5,6 +5,7 @@ import { Levellist } from 'src/app/models/levellist';
import { RequestService } from 'src/app/services/request/request.service'; import { RequestService } from 'src/app/services/request/request.service';
import { DatasharingService } from '../../services/datasharing.service'; import { DatasharingService } from '../../services/datasharing.service';
import { ProfileService } from 'src/app/services/profile/profile.service'; import { ProfileService } from 'src/app/services/profile/profile.service';
import { HttpClient } from '@angular/common/http';
@Component({ @Component({
selector: 'app-profile', selector: 'app-profile',
@ -24,6 +25,7 @@ export class ProfileComponent implements OnInit {
loading = false; loading = false;
constructor( constructor(
private http: HttpClient,
private router: Router, private router: Router,
private requestService: RequestService, private requestService: RequestService,
private data: DatasharingService, private data: DatasharingService,
@ -65,4 +67,14 @@ export class ProfileComponent implements OnInit {
user.allowedToSendRequest = false; user.allowedToSendRequest = false;
this.requestService.sendFriendRequest(user); this.requestService.sendFriendRequest(user);
} }
onFileInput(event) {
console.log(event.target.files[0]);
const formData: any = new FormData();
formData.append('profilePicture', event.target.files[0]);
this.http.post('https://greenvironment.net/upload', formData).subscribe(
(response) => console.log(response),
(error) => console.log(error)
);
}
} }

Loading…
Cancel
Save