@yasirpanjsheri wrote:
hi, I am using
image pickerandcropbut I am failing to upload it correctly.this is the service I am using:
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; }) }the above returns path like this:
file:///storage/emulated/0/Android/data/com.ionicframework.jobsaf211675/cache/1500181851170-cropped.jpg?1500181872091the function for upload:
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) }); }so the result name saved like this:
1500181875074.jpg?1500181872091which is not readable and I cannot download it back... what am I doing wrong here! and which name is the correct one, thanx
Posts: 1
Participants: 1