【问题标题】:What is the best way to save a file reference in Baqend?在 Baqend 中保存文件引用的最佳方法是什么?
【发布时间】:2016-11-14 22:39:20
【问题描述】:

我正在构建一个 Ionic 2 应用程序,它将个人资料图片上传到 Baqend:

import { db } from 'baqend';
const img = new db.File({ folder: '/profiles',  data: imageData, type: 'base64', mimeType: 'image/jpeg' });
img.upload();

我找不到任何类型的文件引用。最好的保存方法是什么?

【问题讨论】:

    标签: ionic2 baqend


    【解决方案1】:

    Baqend 目前不支持文件引用类型,但已计划好。 目前,最好的方法是保存文件的 id 并在加载时从中创建一个文件对象:

    保存:

    img.upload().then(() => {
      let profile = new db.Profile();
      profile.img = img.id
      return profile.save();
    });
    

    加载:

    db.Profile.load('profileId').then(profile => {
      let image = new db.File(profile.img);
      console.log(image.url);
    });
    

    这比简单地保存文件的路径要好得多,因为使用image.url SDK 可以处理缓存失效。这样,您可以简单地将 image.url 分配为 src 给图像元素。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-13
      • 2012-02-18
      • 1970-01-01
      • 2021-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多