Avatar Service in Windows Runtime

0 votes

I am trying to use the Avatar Service and/or the File Upload Service to create and save profile pictures for my app's users on Windows Runtime 8.1 (both Windows Phone and Windows) but I do not exactly understand how to do this. I have a default picture stored as a .png file in my app package that I would like to set as the profile picture when creating a new user. The API call for CreateAvatar says it requires a System.IO.Stream object but I am not sure how to obtain this after I am able to get the file like this:

StorageFile defaultProfilePic = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///profilePic.png"));

So what is the next step to provide this file as a stream to the App42 CreateAvatar API call?

Also Is there a full example which retrieves a file from storage and uploads it and manages avatars for a user on Windows Runtime?
asked Oct 16, 2014 in App42 Cloud API-BaaS by feraask (45 points)

1 Answer

0 votes
Please try this below method
public static async Task<Stream> GetPhotoFromSDCard(String Imageurl)
                StorageFile imgFile = await StorageFile.GetFileFromPathAsync(Imageurl);
                using (Stream fileStream = await imgFile.OpenStreamForReadAsync())
                    StreamReader reader = new StreamReader(fileStream);
                    reader.BaseStream.Seek(0, SeekOrigin.Begin);
                    //BitmapImage bmp = new BitmapImage();
                    return reader.BaseStream;
            catch (Exception e)
                return null;
answered Oct 17, 2014 by errahulpanchal (169 points)
Thanks for the help. I have another question though, is there anyway to delete all the avatar's for a user using the management console? I have tried deleting the user but then when I re-create a user with the same user name and try to add an avatar with the same avatar name as before it says the name still exists. So is there a way to manage the avatar service?

Also, using the App42 SDK for Windows Runtime I cannot seem to delete any avatars as it does not seem to have the methods  avatarService.DeleteAllAvatars() or DeleteAvatarByName() when I access my Avatar Service object.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com