离子2如何HTTP.post图像在离子2/3发送服务器端

时间:2018-02-13 12:29:13

标签: ios ionic-framework server ionic2 ionic-native

我正在使用Ionic 2构建应用程序。我需要从图库或相机拍摄照片并将此照片上传到我的服务器。我有这个代码打开画廊并拍照。没有base64Image,如何上传图片。

   private accessGallery(): void {
        let options = {
          quality: 75,
          // sourceType: this.camera.PictureSourceType.SAVEDPHOTOALBUM,
          // destinationType: this.camera.DestinationType.DATA_URL,
          destinationType: this.camera.DestinationType.FILE_URI,
          sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
          // encodingType: this.camera.EncodingType.JPEG,
          mediaType: this.camera.MediaType.PICTURE
        }

        this.imagePicker.getPictures(options).then((results) => {
          this.imageURI = new Array();
          for (var i = 0; i < results.length; i++) {
            console.log('Image URI: ' + results[i]);
            this.imageURI.push(normalizeURL(results[i]));
          }
          console.log("Body images Name*******:-=" + this.imageURI);
          this.uploadFile();
        }, (err) => { });
}



 uploadFile() {
        let body:any = new FormData();
          body = {
          images: this.imageURI
           }

        let headers = new Headers({
          'token': this.token,
          'sid': this.sid,
          'user': this.user,
          'to': this.to,
          'node': this.node,
          'type': 'image'

        });
        let options = new RequestOptions({ headers: headers });
        console.log("header ----" + JSON.stringify(headers));
        console.log("images data body----" + JSON.stringify(body));

        this.http.post(this.apiURL, body, options)
          .map(res => res.json())
          .subscribe(
          data => {
            console.log(data);
          },
          err => {
            console.log("ERROR!: ", err);
          }
          );
      } 

错误: - 错误!:状态响应:URL为0:null

0 个答案:

没有答案