首页 > 解决方案 > 如何在 Ionic-Angular 应用程序中保存图像(Base64 字符串)

问题描述

我在 azure 中部署了一个后端 rest api。

Angular/Ionic App --> Rest call --> Rest API

Angular/Ionic App <--- image (base64 string) --- Rest API

场景:我在应用程序的多个页面中使用此图像(编码为 base64 字符串),我不想多次调用休息。

离子/角度的当前实现:

export class LoginVerificationService {

constructor(private httpClient: HttpClient,
            public router: Router,
            **@Inject(SESSION_STORAGE) private storage: StorageService,**
            private endpoints: EndpointsConstantsService
) {
}
//method that saves the values in session
setSession(userEmail: string,username:string, age:string, image: string) {
    this.storage.set(this.endpoints.SESSION_EMAIL, userEmail);
    this.storage.set(this.endpoints.SESSION_AGE, age);
    this.storage.set(this.endpoints.SESSION_IMAGE, image);
    this.storage.set(this.endpoints.SESSION_USERNAME, username);
}

我可以保存姓名和年龄,但是当我尝试保存 base64 图像时应用程序崩溃。还有其他方法可以实现吗?

标签: javascriptangularionic-frameworkangular7ionic4

解决方案


推荐阅读