Dicebear and Firebase Storage #271
-
Hey! I am currently working on a profile page system and need to store the user's avatar, which is basically dicebear's identicons using the username, to Firebase. How would I do that? Current code: https://srcb.in/iqFtj3TQRD |
Beta Was this translation helpful? Give feedback.
Answered by
FlorianKoerner
Feb 4, 2023
Replies: 1 comment
-
@magmabits According to the Firebase documentation, the following examples should work. Personally, I would prefer SVG over PNG. pngimport { uploadBytes, ref, getStorage } from 'firebase/storage';
import { createAvatar } from '@dicebear/core';
import { identicon } from '@dicebear/collection';
const username = 'user123';
const storage = getStorage();
const userAvatarRef = ref(storage, `avatars/${username}.png`);
const avatar = await createAvatar(identicon, { seed: username }).png().toArrayBuffer();
await uploadBytes(userAvatarRef, avatar); svgimport { ref, getStorage, uploadString } from 'firebase/storage';
import { createAvatar } from '@dicebear/core';
import { identicon } from '@dicebear/collection';
const username = 'user123';
const storage = getStorage();
const userAvatarRef = ref(storage, `avatars/${username}.svg`);
const avatar = createAvatar(identicon, { seed: username }).toString();
await uploadString(userAvatarRef, avatar); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
FlorianKoerner
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@magmabits According to the Firebase documentation, the following examples should work. Personally, I would prefer SVG over PNG.
png
svg