Esempio n. 1
0
        public HttpResponseMessage GetFile(int departmentId, int id)
        {
            var result = new HttpResponseMessage(HttpStatusCode.OK);

            var attachment = _callsService.GetCallAttachment(id);

            if (attachment == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            // THIS IS A HACK! I've run into issues trying to load images on the mobile app
            // while using the Auth header (img src doesn't support headers)
            if (attachment.Call.DepartmentId != departmentId)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }

            //if (attachment.Call.DepartmentId != DepartmentId)
            //	return Request.CreateResponse(HttpStatusCode.Unauthorized);

            result.Content = new ByteArrayContent(attachment.Data);
            result.Content.Headers.ContentType = new MediaTypeHeaderValue(FileHelper.GetContentTypeByExtension(Path.GetExtension(attachment.FileName)));

            return(result);
        }