如何在 ionic 4 MYSQL & PHP 中将图像上传到数据库?

How to upload images to database in ionic 4 MYSQL & PHP?

我希望你能帮助我我想在我的数据库中插入图像的名称并将文件上传到我的服务器,但我不知道该怎么做

找到了 ionic 3 的教程,但它在 ionic 4 中不起作用,我是这方面的新手。

教程可以在以下名称下找到: "How to upload images from gallery and camera to database in ionic 3 app"

有人知道怎么做吗?

我已经能够修复 Camara 上传和图库访问的问题,但是 "UPLOAD" 我遇到了很多错误,我想这是因为版本问题

Upload(){

  var headers = new Headers();

  headers.append(“Accept”, ‘application/json’);

  headers.append(‘Content-Type’, ‘application/json’ );

  let options = new RequestOptions({ headers: headers });

    let data = {

      image:this.base64Image

    };

  let loader = this.loading.create({

  content: ‘Processing please wait…’,

});

loader.present().then(() => {

this.http.post(‘http://ionicdon.com/mobile/upload_data.php’,data,options)

.map(res => res.json())

.subscribe(res => {

 loader.dismiss()

 if(res==”Successfully_Uploaded”){

   let alert = this.alertCtrl.create({

     title:”CONGRATS”,

    subTitle:(res),

    buttons: [‘OK’]

     });

         alert.present();

 }else {

  let alert = this.alertCtrl.create({

  title:”ERROR”,

  subTitle:”Image could not be uploaded”,

  buttons: [‘OK’]

  });

  alert.present();

   }

 });

 });

  }

一般出现的错误都是代码没有recoze什么

需要 HTTPS

我注意到您正在尝试 post 到 http://ionicdon.com/mobile/upload_data.php。据我所知,最新版本的 Android 需要 https,除非您已完成特殊的设置说明。

新手学习曲线

如果您是新手,那么我不建议您尝试按照 Ionic 3 教程来构建 Ionic 4 应用程序。

很多小东西都变了,很难知道是哪几位(看看 breaking changes 文档有多长)。

Firebase

您可能会通过寻找 Firebase 教程开始获得更大的成功..

这是新手友好的,因为它为您处理所有服务器端的事情,并使您可以轻松实现您将需要的登录和安全性。您找到的任何图片上传教程都可能只是做 "oh this is how to put the image on the server don't forget to secure it, that's out of the scope of the tutorial" 的正常演示风格的事情。

提供了慷慨的免费资源限制,所以如果您只是在学习,您有 space 喘息的机会,当您达到付费限制时,您将能够通过您的观众获利,或者您将更有经验并准备好解决编写自己的 server-side 东西的问题。