How do i send byte[] of converted pdf to Web API?

kavya16kavya16 USMember ✭✭

I have converted my pdf to byte[]. If I send the byte[] to API, it takes the bytes as System.Byte[]. However, I am getting the bytes in my code. Below is the sample of my code:

        string a = files.FileName;
        string c = a.Substring(0, a.LastIndexOf('.')); // removing file extension
     var fileBytes = files.FileBytes.ToArray(); // getting bytes here and then converting into byte array

string url = "http://10.0.2.2/api/Demo/FileData/"+ files.EmpId+ "/" + c+"/"+ filebytes; //files is an Entity with Empid,FileName and FileBytes.
//in my url i am getting url like ****http://localhost/api/Demo/1/sample/System.Byte[] ****

        try
        {
            using (HttpClientHandler clientHandler = new HttpClientHandler())
            using (HttpClient client = new HttpClient(clientHandler))
            {
                using (HttpResponseMessage response = await client.GetAsync(url))
                using (HttpContent content = response.Content)
                {
                    string result = await content.ReadAsStringAsync();
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }

                }
            }

        }

        catch (Exception e)
        {
            return false;
        }
Sign In or Register to comment.