Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70440

Ionic 4 capacitor upload image to server

$
0
0

@Pratikjaiswa15 wrote:

I have used the capacitor plugin to let user capture images and then we can store it in our server(spring).

async takePicture() {
    const image = await Plugins.Camera.getPhoto({
      quality: 100,
      allowEditing: false,
      resultType: CameraResultType.DataUrl,
      source: CameraSource.Prompt, 
    });


    this.photo = this.sanitizer.bypassSecurityTrustResourceUrl(image && (image.dataUrl));

    console.log(this.photo)
    console.log(image)

  }

Now , I want to store image with some other data like name, etc.

servie.ts

httpOptions2 = {
    headers: new HttpHeaders({ 'Content-Type': 'multipart/form-data' })
  };

addReport (user): Observable<any> {
    return this.http.post<any>(this.url , user,this.httpOptions2 )
  }

page.ts

let report = {
        address : this.address.value, // other data 
        image : this.photo,

      }
      console.log(report)

      this.reportService.addReport(report).subscribe(data =>{
        console.log(data)
      })

Input type at the server for the image is the file

I have set ‘Content-Type’: ‘multipart/form-data’.

But at the server-side image is not getting stored?

What am I doing wrong?

Thank you in advance

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70440

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>