コード例 #1
0
        private async Task AddPicture(Applicant applicant, IFormFile thePicture)
        {
            //get the picture and save it with the Patient
            if (thePicture != null)
            {
                string mimeType   = thePicture.ContentType;
                long   fileLength = thePicture.Length;
                if (!(mimeType == "" || fileLength == 0))//Looks like we have a file!!!
                {
                    if (mimeType.Contains("image"))
                    {
                        ApplicantPhoto p = new ApplicantPhoto
                        {
                            FileName = Path.GetFileName(thePicture.FileName)
                        };
                        using (var memoryStream = new MemoryStream())
                        {
                            await thePicture.CopyToAsync(memoryStream);

                            p.FileContent.Content = memoryStream.ToArray();
                            p.MimeType            = mimeType;
                        }
                        applicant.ApplicantPhoto = p;
                    }
                }
            }
        }
コード例 #2
0
        private async Task AddPicture(Applicant applicant, IFormFile thePicture)
        {
            //get the picture and save it with the Applicant
            if (thePicture != null)
            {
                string mimeType   = thePicture.ContentType;
                long   fileLength = thePicture.Length;
                if (!(mimeType == "" || fileLength == 0))//Looks like we have a file!!!
                {
                    if (mimeType.Contains("image"))
                    {
                        ApplicantPhoto p = new ApplicantPhoto
                        {
                            FileName = Path.GetFileName(thePicture.FileName)
                        };
                        using (var memoryStream = new MemoryStream())
                        {
                            await thePicture.CopyToAsync(memoryStream);

                            p.PhotoContentFull.Content   = ResizeImage.shrinkImagePNG(memoryStream.ToArray(), 500, 600);
                            p.PhotoContentFull.MimeType  = mimeType;
                            p.PhotoContentThumb.Content  = ResizeImage.shrinkImagePNG(memoryStream.ToArray(), 100, 120);
                            p.PhotoContentThumb.MimeType = "image/png";
                        }
                        applicant.ApplicantPhoto = p;
                    }
                }
            }
        }