Esempio n. 1
0
        public HttpResponseMessage Get(String itemId)
        {
            var    user = _userSvc.CurrentUser();
            Attach file = _attach.GetById(Guid.Parse(itemId));

            if (file != null && file.UserId != user.Id)
            {
                throw new Exception();
            }

            var key  = HttpContext.Current.Session["FILEKEY"].ToString();
            var data = _crypt.DecryptBytes(file.Data, key);


            var result = new HttpResponseMessage
            {
                Content = new ByteArrayContent(data)
            };

            result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
            {
                FileName = file.Name
            };
            var mime = MimeTypes.GetMimeType(file.Name);

            result.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(mime);
            return(result);
        }