Mini Hulk
Mini Hulk

Reputation: 1

How to send a base64 string or UTF-8 MemoryStream object to Symantec Protection Engine (SPE) in AWS

All the examples I've seen show files being sent to the SPE AWS Virus Scanner api but I have a base64 string or my code has converted this string to a UTF-8 MemoryStream object. The previously implemented Symantec dll had no issues sending this MemoryStream via 512 byte blocks.

In the code below, the myMemoryStream variable was the fileStream variable in the sample code snippet.
When the call is made and the result is parsed, it returns an error: Unsupported Media Type.

Can someone help me figure out what I'm doing wrong?

File code reference snippet:

HttpResponseMessage response = new HttpResponseMessage();
Uri scanUrl = new Uri(hostUrl + "/api/Scan");
HttpClient client = new HttpClient();
using (var fileStream = fileToAdd.OpenReadStream())
{
    var form = new MultipartFormDataContent();
    var streamContent = new StreamContent(fileStream);
    streamContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
    form.Add(streamContent, "documents", fileToAdd.FileName);
    form.Add(new StringContent("NONE"), "composite");

    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
    client.DefaultRequestHeaders.Add("Prefer", "respond-async");
    response = await client.PostAsync(scanUrl, form);

}

My new code:

//resumeFile is a string in base64
byte[] byteArray = Encoding.UTF8.GetBytes(resumeFile);
MemoryStream myMemoryStream = new MemoryStream(byteArray);
...
HttpResponseMessage response = new HttpResponseMessage();
Uri scanUrl = new Uri(hostUrl + "/api/Scan");
HttpClient client = new HttpClient();

var form = new MultipartFormDataContent();
var streamContent = new StreamContent(myMemoryStream);
streamContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
form.Add(streamContent, "documents", fileName);
form.Add(new StringContent("NONE"), "composite");

client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
client.DefaultRequestHeaders.Add("Prefer", "respond-async");
response = await client.PostAsync(scanUrl, form);

dynamic parsed = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());

I tried changing the MediaTypeHeaderValue to text/plain.
Couldn't interrogate the contents of the "parsed" variable to determine if it could tell me more about what was wrong with the call.
What I was expecting was the code to at least give me some better feedback than "Unsupported Media Type". Would be nice if it told me what it found.

Upvotes: 0

Views: 62

Answers (0)

Related Questions