예제 #1
0
        public async Task <HttpResponseMessage> ImportExcelAsync(string username, string password)
        {
            try
            {
                Logger.Info("Calling access token cc api.");
                string folderPath   = ConfigurationManager.AppSettings["FilePath"];
                string access_token = await Authentication.AccessLoginToken(username, password);

                string apiendpoint            = ConfigurationManager.AppSettings["CCAPIEndPoint"] + "api/importexcelresponses";
                var    file_bytes             = File.ReadAllBytes(folderPath);
                MultipartFormDataContent form = new MultipartFormDataContent
                {
                    { new ByteArrayContent(file_bytes, 0, file_bytes.Length), "file", "hello1.xlsx" }
                };
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, apiendpoint);
                request.Content = form;
                request.Headers.Add("Authorization", "Bearer " + access_token);
                Logger.Info("calling bulk import api.");
                httpClient.Timeout = TimeSpan.FromMinutes(30);
                var response = await httpClient.SendAsync(request);

                Console.WriteLine("bulk import api response = " + response.ReasonPhrase + " " + response.StatusCode);
                Logger.Info("bulk import api response = " + response.ReasonPhrase + " " + response.StatusCode);
                return(response);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }