拍照和相册选择后的图片上传

来源:

木头同学

2016-08-04

调用相机和相册都成功返回了图片url,并显示在img标签上,但是不知道怎么把这个url转成file类型上传到服务器。

接口请求参数类型如下:

http://szimg.mukewang.com/57a2d4fd00011f9b07800308.jpg

写回答

1回答

木头同学

提问者

2016-08-07

已解决

参考地址:https://github.com/apache/cordova-plugin-file-transfer

代码如下:

//上传图片 this.img_url:为图片url路径
transferUpLoad() {
  const fileTransfer = new Transfer();
  var options: any;
  options = {
    fileKey: 'image',
    headers: {},
    params: {
      'id': this.id  //需要上传的参数
    }
  }
  fileTransfer.upload(this.img_url, this.uploadImgUrl, options)
    .then((data) => {
      this.helper.presentToast('上传成功!' + data.toString());
    }, (err) => {
      this.helper.presentToast('上传失败!');
    })
}


0
0

Ionic飞速上手的跨平台App开发

以HTML5移动App开发框架Ionic,开发不受平台限制的App

1314 学习 · 640 问题

查看课程