@Pragati PatnaikI couldn't find the resolution for the issue with the http VBO, so I developed below C# code to upload the files.
status = null;
string url = URL; // web api url
string file = FilePath; // path of file to upload
string paramName = "file";
// string contentType = "text/plain";
string username = null;
string password = null;
string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x");
byte[] boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);
foreach (DataRow r in headers.Rows)
{
foreach (DataColumn c in headers.Columns)
{
string columnName = c.ColumnName;
string val = (r[columnName]).ToString();
wr.Headers.Add(columnName, val);
}
}
wr.Headers.Add("Authorization", "Basic");
wr.ContentType = "multipart/form-data; boundary=" + boundary;
wr.Method = "POST";
wr.KeepAlive = true;
Stream rs = wr.GetRequestStream();
string formdataTemplate = "Content-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}";
rs.Write(boundarybytes, 0, boundarybytes.Length);
string headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\nContent-Type: {2}\r\n\r\n";
// var mimeType = MimeMapping.GetMimeMapping(file);
// contentType = MimeMapping.MimeUtility.GetMimeMapping(file);
// string mimeType = System.Web.MimeMapping.GetMimeMapping(file);
string filename = Path.GetFileName(file);
//contentType=MimeMapping.GetMimeMapping(filename);
string header = string.Format(headerTemplate, paramName, filename, contentType);
byte[] headerbytes = System.Text.Encoding.UTF8.GetBytes(header);
rs.Write(headerbytes, 0, headerbytes.Length);
FileStream fileStream = new FileStream(file, FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[4096];
int bytesRead = 0;
while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
{
rs.Write(buffer, 0, bytesRead);
}
fileStream.Close();
byte[] trailer = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n");
rs.Write(trailer, 0, trailer.Length);
rs.Close();
WebResponse wresp = null;
try
{
wresp = wr.GetResponse();
Stream stream2 = wresp.GetResponseStream();
StreamReader reader2 = new StreamReader(stream2);
status = "success";
//log.Debug(string.Format("File uploaded, server response is: {0}", reader2.ReadToEnd()));
}
catch (WebException ex)
{
using (var stream = ex.Response.GetResponseStream())
using (var reader = new StreamReader(stream))
{
status = reader.ReadToEnd();
}
if (wresp != null)
{
wresp.Close();
wresp = null;
}
}
finally
{
wr = null;
}
Hope this helps.