using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using System.Text; namespace SelfSign.Controllers { [ApiController] [Route("api/[controller]")] public class IdxController : ControllerBase { private HttpClient _httpClient; private IConfiguration _configuration; public IdxController(IConfiguration configuration) { Initial(configuration); } private void Initial(IConfiguration configuration) { _httpClient = new HttpClient(); _configuration = configuration; } private void AddResponseHeaders() { var header = HttpContext.Response.Headers.FirstOrDefault(x => x.Key == "Access-Control-Allow-Origin"); if (header.Key == null) { HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*"); HttpContext.Response.Headers.Add("Access-Control-Allow-Headers", "X-Requested-With"); } } [HttpPost("first")] public async Task FirstPhoto([FromForm] IFormFile file) { var keys = _configuration.GetSection("Idx").AsEnumerable(); var response =await PostData(file, keys); return Ok(response); } private async Task PostData(IFormFile file, IEnumerable> keys) { var form = new MultipartFormDataContent(); var fileBytes = new ByteArrayContent(await GetBytes(file)); form.Add(fileBytes,"test","test"); foreach(var key in keys) { form.Add(new StringContent(key.Value), String.Format("\"{0}\"",key.Key)); } var response = await _httpClient.PostAsync("", form); var responseString = await response.Content.ReadAsStringAsync(); return null; } public async Task GetBytes(this IFormFile formFile) { await using var memoryStream = new MemoryStream(); await formFile.CopyToAsync(memoryStream); return memoryStream.ToArray(); } } public class IdxResponse { } }