Example #1
0
        public async Task <ActionResult> GetFile(int fileid, [FromQuery] int?userId)
        {
            if (userId.HasValue && userId > 0)
            {
                await AuthenticateAdmin();
            }
            else
            {
                User user = await AuthenticateUser();

                userId = user.Id;
            }
            GetFileQueryResult stream = await Get <GetFileQuery>().Execute((userId.Value, fileid));

            return(new FileStreamResult(stream.Data, stream.ContentType));
        }
Example #2
0
        public async Task <ActionResult> GetImage(int fileid)
        {
            User user = await AuthenticateUser();

            using (GetFileQueryResult stream = await Get <GetFileQuery>().Execute((user.Id, fileid)))
                using (Image image = Image.FromStream(stream.Data))
                    using (MemoryStream m = new MemoryStream())
                    {
                        image.Save(m, image.RawFormat);
                        byte[] imageBytes   = m.ToArray();
                        string base64String = Convert.ToBase64String(imageBytes);

                        return(Ok(new
                        {
                            file = base64String,
                            contentType = stream.ContentType,
                            contentEncoding = "base64"
                        }));
                    }
        }