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

Upload multiple files with formdata please guide

$
0
0

@Nikhil_dhar123 wrote:

here please check below code

public takePicture(sourceType, DestinationType) {
    var options = {
      quality: 100,
      sourceType: sourceType,
      destinationType: DestinationType,
      saveToPhotoAlbum: true,
      correctOrientation: true,
      mediaType: 2
      // allowEdit : true
    };
    this.camera.getPicture(options).then((imagePath) => {
      if (this.platform.is('android') && sourceType === this.camera.PictureSourceType.PHOTOLIBRARY) {
        this.filePath.resolveNativePath(imagePath)
          .then(filePath => {
            this.lastImage = this.createFileName();
            this.selectedImagePath = imagePath;
          });
      } else {
        this.lastImage = this.createFileName();
        this.tempPath = "data:image/jpeg;base64," + imagePath;
        this.selectedImagePath = imagePath;
      }
    }, (err) => {
      this.presentToast(err);
    });
  }

  private createFileName() {
    var d = new Date(),
      n = d.getTime(),
      newFileName = n + ".jpg";
    return newFileName;
  }

The above code will give me the images and and the path in "imagePath" that I am storing in an array and the "tempPath" is for displaying on signature that is working fine now but for uploading the multiple files like in below code how to send that I am not getting
Please check below code;;

public uploadImage() {

    let body: string = JSON.stringify({'postData': this.postData}); //here post data is like this this.postData.push({key:this.selectedImagePath},{key:this.selectedImagePath}); here I have to use formData
    // type: 'application/json',
    let headers: any = new Headers({ 'Content-Type': 'application/json' }),
      options: any = new RequestOptions({ headers: headers }),
      url: any = this.uploadUrl;

    this.http.post(url, body, options)
      .subscribe((data) => {
        let message = data["_body"];
        message = JSON.parse(message);
        if (message.success == true) {
          window.localStorage.setItem("id", message.user_id);
          window.location.reload();
        }

        else {
          let alert = this.alertCtrl.create({
            title: 'Error',
            subTitle: message.message,
            buttons: ['OK']
          });
          alert.present();
        }
      });
  }

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 71530

Trending Articles



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