0

I have image in the form of byte[] data and code to pass byte data to get response from client. I need help in putting them together

I tried to use the code where I have my byte data but the async operations created a lot of confusion

"data" contains the byte[] data

  private async void InitializeVideoFeedModule()
        {
            //Must in UI thread
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            {
                //Raw data and decoded data listener
                if (videoParser == null)
                {
                    videoParser = new DJIVideoParser.Parser();
                    videoParser.Initialize( delegate (byte[] data)
                    {
                        return DJISDKManager.Instance.VideoFeeder.ParseAssitantDecodingInfo(0, data);

                    });
                }
             }
         }

code to pass byte data and get response

var client = new HttpClient();
client.DefaultRequestHeaders.Add("Prediction-Key", "XXXXX");

// Prediction URL - replace this example URL with valid Prediction URL.
string sequenceURL = "https://abc/dcr/xyz";
HttpResponseMessage response;

using (var content = new ByteArrayContent(data))
{
   content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
   response = await client.PostAsync(sequenceURL, content);
  var output = await response.Content.ReadAsStringAsync();
   Console.WriteLine(output);

   JObject json = JObject.Parse(output);

}

The delegate object and async operations are causing conflicts when I use them together.

5
  • Are you wanting to send it as a byte array, a stream, or something different? Commented Oct 17, 2019 at 21:01
  • @MitchWilkins I’m trying to send it as a byte array Commented Oct 17, 2019 at 21:02
  • can you post the errors you're getting? Commented Oct 17, 2019 at 21:08
  • You want to run an async delegate that doesn’t make use of await and have it run in the UI thread? I don’t see that you’re getting any benefit from the async/await pattern by doing this...
    – joehoper
    Commented Oct 17, 2019 at 21:22
  • @joehoper my end result it to pass the data and get the response. I got the byte[] data from a sample code which I am sending to client. I you think there is a different way to achieve this please let me know Commented Oct 18, 2019 at 15:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.