Esempio n. 1
0
        public IActionResult DownloadAttachmentsAsStream([FromBody] MailAttachmentDetails mailAttachmentDetails)
        {
            try
            {
                #region Error Checking
                GenericResponseVM genericResponse = null;
                if (mailAttachmentDetails == null && mailAttachmentDetails.FullUrl == null)
                {
                    genericResponse = new GenericResponseVM()
                    {
                        Value   = errorSettings.MessageNoInputs,
                        Code    = HttpStatusCode.BadRequest.ToString(),
                        IsError = true
                    };
                    return(matterCenterServiceFunctions.ServiceResponse(genericResponse, (int)HttpStatusCode.OK));
                }
                #endregion
                Stream downloadAttachments = documentProvision.DownloadAttachments(mailAttachmentDetails);

                var fileContentResponse = new HttpResponseMessage(HttpStatusCode.OK);
                fileContentResponse.Headers.Clear();

                fileContentResponse.Content = new StreamContent(downloadAttachments);

                fileContentResponse.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(DocumentProvision.ReturnExtension(string.Empty));
                //fileContentResponse.Headers.Add("Content-Type", ReturnExtension(string.Empty));
                fileContentResponse.Content.Headers.Add("Content-Length", downloadAttachments.Length.ToString());
                fileContentResponse.Content.Headers.Add("Content-Description", "File Transfer");

                //application/octet-stream
                fileContentResponse.Content.Headers.Add("Content-Disposition", "attachment; filename=" + documentSettings.TempEmailName + new Guid().ToString() + ServiceConstants.EMAIL_FILE_EXTENSION);
                fileContentResponse.Content.Headers.Add("Content-Transfer-Encoding", "binary");
                fileContentResponse.Content.Headers.Expires = DateTimeOffset.Now.AddDays(-1);;
                fileContentResponse.Headers.Add("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
                fileContentResponse.Headers.Add("Pragma", "public");
                var fileAttachmentContent = fileContentResponse.Content.ReadAsStringAsync();
                var response = new
                {
                    fileAttachment = fileAttachmentContent,
                    fileName       = documentSettings.TempEmailName + Guid.NewGuid().ToString() + ServiceConstants.EMAIL_FILE_EXTENSION
                };
                return(new ObjectResult(response));
            }
            catch (Exception ex)
            {
                customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }
        }