1

I'm building an Ionic 2 app, which uploads a profile image to Baqend:

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

I can't find any type for a file reference. Whats the best way to save it?

4

1 回答 1

3

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.urlSDK 会处理缓存失效。这样,您可以简单地分配image.urlsrc图像元素。

于 2016-11-03T18:16:59.087 回答