コード例 #1
0
        public async Task <IHttpActionResult> UploadImage()
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            var person     = SecurityPrincipal.Current;
            var role       = person.Role;
            var file       = HttpContext.Current.Request.Files[0];
            var fileLength = file.ContentLength;

            byte[] filebytes = new byte[fileLength];

            var stream = file.InputStream;

            stream.Read(filebytes, 0, fileLength);

            if (role.Equals("Parent", System.StringComparison.InvariantCultureIgnoreCase))
            {
                await _parentsService.UploadParentImageAsync(person.PersonUniqueId, filebytes, file.ContentType);
            }
            else
            {
                await _teachersService.UploadStaffImageAsync(person.PersonUniqueId, filebytes, file.ContentType);
            }

            return(Ok());
        }