Hubspot API File Manager Upload Issues using C#, but working when i used postman



I am not able to upload an image using C# HttpWebRequest, but i tried with postman it’s working

i am using below code

string HubSpotkey = ConfigurationManager.AppSettings[“HubSpotkey”];
string file = @“C:\Users\sandeep.pothireddy\Downloads\HtmlToImage.png”;
var httpWebRequest = (HttpWebRequest)WebRequest.Create(“” + HubSpotkey);

            string buffer = Convert.ToBase64String(System.IO.File.ReadAllBytes(file));

            string boundary = "----WebKitFormBoundary" + DateTime.Now.Ticks.ToString("x");
            httpWebRequest.ContentType = "multipart/form-data; boundary=" + boundary;
            httpWebRequest.Method = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                var result = streamReader.ReadToEnd();


Hi @sandeeprdy.p,

I’m not fluent in C#, so I’m not the best resource to help troubleshoot your code. I was able to find a couple of examples of C# multipart form submissions online that might be helpful: