Как загрузить файл с помощью плагина для передачи файлов в ionic3? - PullRequest
0 голосов
/ 07 февраля 2020

Я хочу отправить одно изображение на сервер с другими параметрами. Но не удалось отправить изображение на сервер. уже установлен @ ioni c -native / file-Transfer

Вот мой код в ioni c 3 для передачи файла на php сервер:

var fileURL = this.picData;
      var params: any = {};
      params.action = 'updateProfile';
      params.user_id = this.user_id;
      params.service_id = data.userInterested;

  let headers = new Headers();
  headers.append('Content-Type', 'multipart/form-data');
  headers.append('Access-Control-Allow-Origin', '*');
  headers.append('Access-Control-Allow-Headers', 'X-Requested-With');
  var options: FileUploadOptions = {
    fileKey: "file",
    fileName: this.filename,
    headers: headers,
    params: params
  };

  const fileTransfer: FileTransferObject = this.transfer.create();
  fileTransfer.upload(fileURL, encodeURI(this.apiService.base_url + this.apiService.update_profile),
    options)
    .then((data) => {
      // success
      this.loading.dismissAll()
      alert("success" + JSON.stringify(data));
    }, (err) => {
      // error
      this.loading.dismissAll()
      alert("error" + JSON.stringify(err));
    });

Ошибка:

body:"<!DOCTYPE html>\n\t<html>\n\t  <head>\n\t\t<meta name="viewport" content="width=device-width, initial-scale=1">\n\t\t<meta charset="utf-8">\n\t\t<title>Application Error</title>\n\t\t<style media="screen">\n\t\t  html,body,iframe {\n\t\t\tmargin: 0;\n\t\t\tpadding: 0;\n\t\t  }\n\t\t  html,body {\n\t\t\theight: 100%;\n\t\t\toverflow: hidden;\n\t\t  }\n\t\t  iframe {\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t\tborder: 0;\n\t\t  }\n\t\t</style>\n\t  </head>\n\t  <body>\n\t\t<iframe src="//www.herokucdn.com/error-pages/application-error.html"></iframe>\n\t  </body>\n\t</html>"
code:1
exception:"https://cors-anywhere.herokuapp.com/http://example.in/api.php"
http_status:503
source:"file:///storage/emulated/0/Android/data/io.ionic.starter/cache/1580985138657.jpg"
target:"https://cors-anywhere.herokuapp.com/http://example.in/api.php
...