Uploading pictures


#1

Hi,

I have a form with text input and i want to add picture file and upload it using api laravel…
And have a picture preview.
Any code example ?

I already did this but don’t know if it’s the best way to do

<div [formGroup]="sinistreForm">
    <ion-item>
      <ion-input type="text" placeholder="Nom conducteur" formControlName="iNom" [(ngModel)]="userData.NomConducteur"></ion-input>
    </ion-item>
    <ion-item>
      <ion-input type="number" pattern="[0-9]*" placeholder="Tel conducteur" formControlName="iTel" [(ngModel)]="userData.TelConducteur"></ion-input>
    </ion-item>
    <ion-item>
      <ion-input type="text" placeholder="CIN conducteur" formControlName="iCin" [(ngModel)]="userData.CinConducteur"></ion-input>
    </ion-item>
    <ion-item (click)="getUserPosition()">
      <ion-input type="text" disabled formControlName="iLongitude" value="Longitude : {{lo}}"></ion-input>
    </ion-item>
    <ion-item (click)="getUserPosition()">
      <ion-input type="text" disabled formControlName="iLatitude" value="Latitude : {{la}}"></ion-input>
    </ion-item>
    <ion-item>
      <ion-input type="file"  formControlName="iJustif1" [(ngModel)]="justif1"></ion-input>
    </ion-item>
    
    <br>
  
    <button ion-button color="positive" full (click)="declarerSinistre()" [disabled]="!sinistreForm.valid" block>Déclarer</button>
  </div>

And the TS file i only have

 declarerSinistre(){
    var headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');

    var params = 'ClientId='+1+'&NomConducteur='+this.userData.NomConducteur+'&TelConducteur='+this.userData.TelConducteur+'&CinConducteur='+this.userData.CinConducteur+'&latitude='+this.la+'&longitude='+this.lo;
    this.http.post(this.apiSinistre, params , {headers: headers})
      .subscribe(
        data => this.afficherAlert('Réussite','Sinistre Déclaré'),
        err => this.afficherAlert('Erreur','Sinistre Non Déclaré')
      );
  }