ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

Failed to show image (base64) using async pipe after upgrade from RC3 to RC4

Open lufias opened this issue 9 years ago • 6 comments

Ionic version: (check one with "x") [ ] 1.x [x ] 2.x

I'm submitting a ... (check one with "x") [x ] bug report [ ] feature request [ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/

Current behavior:

Upgrading from RC3 to RC4. Using async pipe to resolve user id into image (in base 64 format) from either locally saved cache or fresh from server. The data (base 64) is sucessfully grabbed from within the pipe, but not get updated in the view. Working perfect in RC3 but failed in RC4. Debugger keep pointing to this line in img.js file.

selection_016

Expected behavior:

Image will show after a while.

Steps to reproduce:

Related code:

The pipe:

import {Pipe, PipeTransform} from '@angular/core'
import {ImageHandlerUtilities} from '../ImageHandler'
import qlib from 'q'

@Pipe({
	name:'resolveImage'
})
export class ImageResolverPipe implements PipeTransform {

	constructor(public imageHandler:ImageHandlerUtilities){}

	transform(value:number, type:string){
		
		var deferred = qlib.defer()

		if(value){			
			// user profile image
			if(type === 'CXPerson'){
				
				this.imageHandler.getProfileImageByUserId(value).then(
					(res:string)=>{	
						// base 64 data 
						deferred.resolve(res)
					},
					(error)=>{
						error.unshift({ loc: 'ImageResolverPipe:transform:ix-1 ' })
						console.error(error)
					}
				)	
			}
			// team profile image
			else if(type === 'CXTeam'){
				this.imageHandler.getTeamProfileImageByTeamId(value).then(
					(res:string)=>{
						// base 64 data
						deferred.resolve(res)
					},
					(error)=>{
						error.unshift({ loc: 'ImageResolverPipe:transform:ix-2 ' })
						console.error(error)
					}
				)	
			}
		}
		else{
			// default random dummy image
			deferred.resolve('http://lorempixel.com/g/100/100/people/')
		}

		
		return deferred.promise
	}

}

Usage example: <ion-img [src]="user_id | resolveImage:'CXPerson' | async"></ion-img>

Other information:

Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):

Your system information:

Cordova CLI: 6.3.1 
Ionic Framework Version: 2.0.0-rc.4
Ionic CLI Version: 2.1.17
Ionic App Lib Version: 2.1.7
Ionic App Scripts Version: 0.0.47
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Linux 4.4
Node Version: v6.7.0
Xcode version: Not installed

lufias avatar Dec 18 '16 13:12 lufias

I've made a simple example based on ionic 2 tutorial demo if you want to give it a try.

https://github.com/lufias/ionic-image-sync

This time, I simply resolve a string right away from within the pipe. The string will be later attached to ion-img src attributes.

Pipe:

@Pipe({
	name:'resolveImage'
})
export class ImageResolverPipe implements PipeTransform {

	constructor(){}

	transform(value:number){
		
		var deferred = qlib.defer()
	  deferred.resolve('data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCws..

But debugger still throw me error of 'Cannot read property indexOf null' which is the 'newSrc' object in img.js.

selection_017

lufias avatar Dec 18 '16 14:12 lufias

Comparing img.ts from both RC3 and RC4, i saw quite some changes. It appear to me that in RC3 there is some kind of check to see if the src truly present before proceed any futher.

lufias avatar Dec 18 '16 15:12 lufias

I end up replacing all ion-img with html own img tag..

lufias avatar Dec 19 '16 02:12 lufias

Hello! Sorry you are running into issues here, we will look into this!

jgw96 avatar Dec 21 '16 18:12 jgw96

Ok, I got it to work after change [src]="" to src="{{}}".

<ion-img src="{{(myimg | async)?.url}}" style="width: 100%; height: 160px;" cache="true"></ion-img>

eusthace811 avatar Jan 16 '17 23:01 eusthace811

Thanks for the issue! This issue is being closed due to inactivity. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

Thank you for using Ionic!

ionitron-bot[bot] avatar Mar 26 '18 17:03 ionitron-bot[bot]