I have a document docx file which is more than 30 MB. I want to send this document to one API to another API. I have tried different ways but it takes around 1 or more second for process. I need to achieve same thing in milliseconds.
What is best and time efficient way to achieve this please help me.
Below codes i have tried :
Client Side
var templatebyteArray = System.IO.File.ReadAllBytes(@"C:UsersrprajapatiDownloadsTableData-out.docx"); // template byte array
var authorization = HttpContext.Request.Headers["Authorization"];
var Test30MBDoc = new Test30MBDoc { CurrentTime = starttime, DocArray = templatebyteArray };
var content = Serialize(Test30MBDoc);
using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient())
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, testUrl);
request.Content = new StringContent(content, Encoding.UTF8, "application/json");
request.Headers.Add("Authorization", authorization[0]);
var response = await client.SendAsync(request);
}
Server Side
[HttpPost]
[Route("receiver1")]
public async Task<IActionResult> Index(Test20MBDoc array)
{
try
{
// transport time take around 1 second
}
}
Second Thing i tried to send the template into chunks using multipart request"
Client Side :
var templatebyteArray = System.IO.File.ReadAllBytes(@"C:UsersrprajapatiDownloadsTableData-out.docx");; // template byte array
int MAX_SUB_SIZE = 5242880; // 5*1024*1024 == 5MB
MultipartFormDataContent multiPartContent = new MultipartFormDataContent();
int i = 1;
foreach (byte[] chunk in templatebyteArray.Chunk(MAX_SUB_SIZE))
{
ByteArrayContent byteArrayContent = new ByteArrayContent(chunk);
byteArrayContent.Headers.Add("Content-Type", "application/octet-stream");
multiPartContent.Add(byteArrayContent, "byte content", $"chunk{i}");
i++;
}
var authorization = HttpContext.Request.Headers["Authorization"];
using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient())
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, testUrl);
request.Content = multiPartContent;
request.Headers.Add("Authorization", authorization[0]);
var response = await client.SendAsync(request);
}
Server Side:
[HttpPost]
[Route("receiver")]
public async Task<IActionResult> Index()
{
// transport time takes around 0.5 second but Need to convert chunks into template again it takes around 300 ms
}
New contributor
user24973368 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.