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?
A file reference type is currently not supported by Baqend, but it's planed. Currently, the best way is to save the id of the file and create a file object from it when loading:
Save:
img.upload().then(() => {
let profile = new db.Profile();
profile.img = img.id
return profile.save();
});
Load:
db.Profile.load('profileId').then(profile => {
let image = new db.File(profile.img);
console.log(image.url);
});
This is much better than simply saving the path of the file because with image.url
the SDK handles the cache invalidation. This way you could simply assign image.url
as src
to an image element.