Exemple #1
0
        public async Task <IActionResult> ShareDownloadFile([FromBody] AttachmentDownloadResource attchDownload)
        {
            string fileName;
            string fileLoc = string.Empty;
            var    msmstr  = new MemoryStream();

            try
            {
                fileName = "Fiesta_1.6L_PowerShift.pdf";

                if (String.IsNullOrEmpty(fileName))
                {
                    this.ErrorMessage.Add("File name invalid.");
                }

                var path = Path.Combine(@"D:\Doument\Other\");
                fileLoc = string.Format("{0}{1}", path, fileName);

                using (var stream = new FileStream(fileLoc, FileMode.Open))
                {
                    await stream.CopyToAsync(msmstr);
                }
            }
            catch (Exception e)
            {
                this.ErrorMessage.Add(e.Message);
            }


            if (this.ErrorMessage.IsError)
            {
                return(Content(this.ErrorMessage.ToString()));
            }
            else
            {
                msmstr.Position = 0;
                return(File(msmstr, this.FileContentType.GetContentType(fileLoc), Path.GetFileName(fileLoc)));
            }
        }
Exemple #2
0
        public IActionResult CreditCheckDownloadFile([FromBody] AttachmentDownloadResource attchDownload)
        {
            this.Utility.CheckStringIsEmpty(this.ErrorMessage, string.Format("Category invalid.: {0}", attchDownload.Category), attchDownload.Category);
            this.Utility.CheckStringIsEmpty(this.ErrorMessage, string.Format("Application No invalid.: {0}", attchDownload.AppId), attchDownload.AppId);
            this.Utility.CheckStringIsEmpty(this.ErrorMessage, string.Format("Display name invalid.: {0}", attchDownload.DisplayFilePath), attchDownload.DisplayFilePath);

            if (!this.ErrorMessage.IsError)
            {
                string url       = $"{AppSettingJsonConfiguration["Server:FileServer"]}";
                string urlMethod = $"{AppSettingJsonConfiguration["Server:DownloadMethod"]}";

                var client = new RestClient(new Uri(url));

                var request = new RestRequest(urlMethod, Method.POST);
                request.RequestFormat = DataFormat.Json;
                request.AddBody(new
                {
                    AppId           = "testAc012",
                    ategory         = "cat1",
                    CustomerId      = "00001",
                    DisplayFilePath = "xxxxx"
                });

                client.AddDefaultHeader("Content-Type", "application/json");
                string token = ((FrameRequestHeaders)this.Request.Headers).HeaderAuthorization;
                client.AddDefaultHeader("Authorization", token);

                var restRep = client.Execute(request);

                var resp = restRep.Content;

                return(Content(resp));
            }
            else
            {
                return(Content(this.ErrorMessage.ToString()));
            }
        }