Search code examples
javascriptc#filearraybuffer

What is the best way to send array buffer from React client to C# server?


I have an array buffer that created from pdf file, I have to send that data to the server side. What is the type C# may want to get? What type should I send from the client side? not sure what is the helpful way.


Solution

  • I got it by:

    The client side:

        const formData = new FormData()
        formData.append('file', new Blob([fileData]))
        const options: any = {
          method: 'POST',
          body: formData
        }
    
        fetch(url,options).then(res=>...)
    

    The server function:

    [HttpPost]
    public ActionResult UploadFile(IFormFile file)
    {
        // process the uploaded file
    }