public async Task <ChadderError> DownloadPicture(ChadderPicture picture)
        {
            var response = await Session.PostRequestAPI <BasicResponse <byte[]> >(Urls.DownloadBlob, picture.Id);

            if (response.Error == ChadderError.OK)
            {
                var packed = Content.Deserialize(response.Extra);
                if (packed == null)
                {
                    Insight.Track("Not a valid content");
                    return(ChadderError.INVALID_INPUT);
                }
                if (packed is ImageContent)
                {
                    var record = new ChadderSQLPicture()
                    {
                        PictureId    = picture.Id,
                        Bin          = (packed as ImageContent).BinData,
                        ToBeUploaded = false
                    };
                    await sqlDB.InsertAsync(record);

                    picture.RecordId = record.recordId;
                    return(ChadderError.OK);
                }
                else
                {
                    Insight.Track("Not a ImageContent");
                    return(ChadderError.INVALID_INPUT);
                }
            }
            return(response.Error);
        }
        public async Task <BasicResponse <string> > UploadPicture(ChadderSQLPicture record)
        {
            var packed = new ImageContent()
            {
                BinData = record.Bin
            }.Serialize();

            var response = await Session.PostRequestAPI <BasicResponse <string> >(Urls.UploadBlob, packed);

            if (response.Error == ChadderError.OK)
            {
                var picture = db.GetPicture(record.PictureId);
                picture.Id           = response.Extra;
                picture.ToBeUploaded = false;
                record.PictureId     = response.Extra;
                record.ToBeUploaded  = false;
                await sqlDB.UpdateAsync(record);
            }
            return(response);
        }
        public async void SendPicture(byte[] data, ChadderConversation conversation)
        {
            var record = new ChadderSQLPicture()
            {
                ToBeUploaded = true,
                Bin          = data,
                PictureId    = Guid.NewGuid().ToString()// Temporary
            };

            await sqlDB.InsertAsync(record);

            var picture = await db.LoadPicture(record, true);

            var msg = ChadderMessage.Create(conversation, db.LocalUser, ChadderMessage.MESSAGE_TYPE.PICTURE);

            msg.PictureId = record.PictureId;
            msg.Picture   = picture;

            await db.AddMessage(msg, conversation);

            AddPendingMessage(msg);
        }
        public async Task <BasicResponse <string> > UploadPicture(byte[] data)
        {
            var packed = new ImageContent()
            {
                BinData = data
            }.Serialize();

            var response = await Session.PostRequestAPI <BasicResponse <string> >(Urls.UploadBlob, packed);

            if (response.Error == ChadderError.OK)
            {
                var record = new ChadderSQLPicture()
                {
                    PictureId    = response.Extra,
                    Bin          = data,
                    ToBeUploaded = false
                };
                await sqlDB.InsertAsync(record);

                await db.LoadPicture(record, true);
            }
            return(response);
        }