Closed MastalerzKamil closed 3 years ago
What code is exactly throwing an exception? Show us the stack trace with the message. Isn't that a serialization issue - from the serialization library that RestSharp uses? How big is the frame in kilobytes?
Alright, my problem has been solved. @Toumash was right, RestSharp might be problematic. The more simple way was using HttpClient.
Here is a method which do that:
private async void SendPicture(string frameName, byte[] frameData)
{
var client = new HttpClient();
var formDataContent = new MultipartFormDataContent();
var fileContent = new ByteArrayContent(frameData);
fileContent.Headers.ContentType = new MediaTypeHeaderValue("image/png");
var fileName = $"{frameName}.png";
formDataContent.Add(fileContent, "image", fileName);
var namePair = new KeyValuePair<string, string>("name", frameName);
formDataContent.Add(new StringContent(namePair.Value), namePair.Key);
var response = await client.PostAsync("http://127.0.0.1:5002/predict", formDataContent);
}
The issue has been also connected with sending pixels instead of bytes array converted to PNG format. I've converted Image<Bgr24>
into bytes[]
of PNG image by using SixLabors
library.
var framePixels = file.Video.ReadFrame(i).ToBitmap();
var ms = new MemoryStream();
framePixels.SaveAsPng(ms);
var frameAsPng = ms.ToArray();
What I need to do is getting frame and convert that to
byte[]
format to send it to another microservice. Is that conversion possible? I know that there is propertySpan<byte>
and then useToArray()
but it didn't work and RestSharp throw an exception.