Suggestion about Avatars storage

Hello ! We are building a mobile game with Unity and Nakama, we need to upload custom profile avatars for each user, as I see in the documentation there is an “avatar_url” field but there is no way to upload the avatar picture using nakama, so I think we could handle this by our own.

We are working on Google Cloud so we decided to use Google Cloud Storage, but it has the drawback to allow users’ authentication only through Firebase, so we can’t upload pictures directly from the client.

We thought about 2 possible solutions:

  1. Serialize the avatar in base64 and pass it to a go runtime function through the payload of the rpc call, which will validate the user and eventually upload the image on Google Cloud Storage and update the user’s avatar url.
  2. Make a custom service that will receive the avatar through a post request with the nakama token, validate the user with his token calling the nakama service and then eventually upload the image on Google Cloud Storage and update the user’s avatar url.

What do you think ? Do you have some best practices for this ?

Hi @GUIZARD! Both your suggestions should work fine, the first one is probably easier because it avoids you needing a new service.

You can also consider storing avatars as base64 strings in the storage API, and making the user’s avatar_url field a storage collection and key name combination. This would also be done through an RPC function.

In all cases I’d recommend both limiting the upload size from the client, and processing the uploaded image in the RPC function to strip out metadata, resize it to your maximum size/ratio, validating that it’s a valid image and not video/audio/random junk data etc. You should also give some thought to moderation, some user somewhere out there will definitely try uploading an inappropriate image.

1 Like