如何上传裁剪的图片

时间:2017-07-16 05:51:30

标签: angular ionic2 ionic3

我正在使用image pickercrop,但我无法正确上传。

这是我正在使用的服务:

getMedia(): Promise<any> {
 return this.imagePicker.getPictures(this.options).then((fileUri) => {
    if (this.platform.is('ios')) {
      return fileUri
    } else if (this.platform.is('android')) {
      fileUri = 'file://' + fileUri;
      /* Using cordova-plugin-crop starts here */
      return this.crop.crop(fileUri, { quality: 100 });
    }
 })
 .then((path) => {
   console.log('path in .then((path)): ', path)
   return path;
 })
}

上面的返回路径如下:file:///storage/emulated/0/Android/data/com.ionicframework.jobsaf211675/cache/1500181851170-cropped.jpg?1500181872091

上传功能:

    async upload(): Promise<void> {

    let url = 'valid URL';
    let options = {
       fileKey: 'file',
       fileName: this.selectedImage.split('/').pop(),
       mimeType: 'image/jpeg',
       chunkedMode: false,
     };

     console.log('options from upload: ', options)   // this returns fileName: `1500181851170-cropped.jpg?1500181872091`

     this.fileTransfer.upload(this.selectedImage, this.URL, options, false).then(res => {
     if (res.responseCode === 200){
         let data = JSON.parse(res.response);

         const ProfilePicInfo = {
            name: data['result']['files']['file'][0].name,
            mime: data['result']['files']['file'][0].type,
            size: data['result']['files']['file'][0].size
         };

         console.log('ProfilePicInfo: ', ProfilePicInfo);  // the name object here changes , the field name here is --> `name: "1500181875074.jpg?1500181872091"`

         this.profilePicService.postProfilePic(url, ProfilePicInfo).subscribe(res => {
           console.log('result after posting pic: ', res)
         }, err => {
          console.log('error posting profile pic: ', err)
       });
     }
   }, err => {
      console.log('image upload failed: ', err)
   });
 }

所以结果名称保存如下:1500181875074.jpg?1500181872091这是不可读的,我无法下载...我在这里做错了什么!哪个名称是正确的,thanx

0 个答案:

没有答案