Stack Overflow Asked by Rakesh on August 2, 2020
I am trying cast a Json data to byte array and then save it in SQL image field, code is below
public string Post([FromBody] dynamic data)
{
foreach (var item in data)
{
imgPhoto1 = (byte[])item["Photo1"];
}
}
But getting error Can not convert Array to byte array
byte[] imgPhoto1 = (byte[])item["Photo1"];
Values in field item["Photo1"] is look like below
[255,216,255,224]
any help will be appreciated
If your parameter data
is JToken
, then you need convert it to desired type.
Try to use:
var obj = item["Photo1"].ToObject<byte[]>();
And will be better explicit declare your parameter data
as JToken
.
Correct answer by Alex69rus on August 2, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP