I was succeeded to upload file to the gateway via SandBlast Chrome extension, but not via code.
I also was succeeded to perform a query from code to the local gateway.
But it fails when I try to upload a file to local gateway it always return "Bad request" "Invalid Multipart/form request", I have added my C# code:
static void Main(string[] args)
{
MainAsync(args).Wait();
}
static async Task MainAsync(string[] args)
{
string json = "{\r\n\t\"request\": {\r\n\t\t\"md5\": \"44D88612FEA8A8F36DE82E1278ABB02F\",\r\n\t\t\"file_name\": \"TestEicar.pdf\",\r\n\t\t\"file_type\": \"pdf\",\r\n\t\t\"features\": [\"te\"],\r\n\t\t\"te\": {\r\n\t\t\t\"reports\": [\"pdf\", \"xml\"],\r\n\t\t\t\"images\": [{\r\n\t\t\t\t\"id\": \"7e6fe36e-889e-4c25-8704-56378f0830df\",\r\n\t\t\t\t\"revision\": 1\r\n\t\t\t}, {\r\n\t\t\t\t\"id\": \"e50e99f3-5963-4573-af9e-e3f4750b55e2\",\r\n\t\t\t\t\"revision\": 1\r\n\t\t\t}]\r\n\t\t}\r\n\t}\r\n}";
Console.WriteLine(json);
ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
var path = @"C:\Users\066570516\Desktop\TempEicar.pdf";
var url = "https://172.45.1.122:18194/tecloud/api/v1/file/upload";
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "MyAPIKEY");
//add json byte array to mulipart
MultipartFormDataContent form = new MultipartFormDataContent("----WebKitFormBoundary7MA4YWxkTrZu0gW");
byte[] jsonByte = Encoding.ASCII.GetBytes(json);
var jsonContent = new ByteArrayContent(jsonByte);
jsonContent.Headers.Add("Content-Disposition", "form-data; name=\"request\"");
jsonContent.Headers.Add("Content-Type", "application/json");
form.Add(jsonContent);
//add file stream to multipart
FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
var streamContent = new StreamContent(fs);
streamContent.Headers.Add("Content-Disposition", "form-data; name=\"file\"; filename=\"" + Path.GetFileName(path) + "\"");
streamContent.Headers.Add("Content-Type", "application/pdf");
form.Add(streamContent);
HttpResponseMessage response = await httpClient.PostAsync(url, form);
response.EnsureSuccessStatusCode();
httpClient.Dispose();
Console.WriteLine(response.Content.ReadAsStringAsync().Result);
}