I have project where a user side framework written in PHP uses file_get_contents to read image files and place the output string into DB which then used to display the image to user by reading from DB.
Now i am making a webservice(webAPI in c#) by which user sends image in a byte[] from mobile app. and I need to find the exact alternate mathod for file_get_contents for C#.
Searched through out the web and found out two ways.
byte[] fileData = File.ReadAllBytes(filePath); string sContents = System.Text.Encoding.ASCII.GetString(fileData);
StreamReader sr = new StreamReader(filePath); string sContentsa = sr.ReadToEnd(); sr.Close();
from a sample image file the output for different methods are:
file_get_contents gives : {�PNG\r\n\n\0\0\0\rIHDR\0\0�\0\0�\b\0\0\0���(\0\0\0\tpHYs\0\0\v\0\0\v\0��\0\0\nOiCCPPhotoshop ICC profile\0\0xڝSgTS�}
First c# method: ?PNG\r\n\n\0\0\0\rIHDR\0\0?\0\0?\b\0\0\0???(\0\0\0\tpHYs\0\0\v\0\0\v\0??\0\0\nOiCCPPhotoshop ICC profile\0\0x?SgTS
second c# method: �PNG\r\n\n\0\0\0\rIHDR\0\0�\0\0�\b\0\0\0���(\0\0\0\tpHYs\0\0\v\0\0\v\0��\0\0\nOiCCPPhotoshop ICC profile\0\0xڝSgTS�
So looks like second c# method generates the same output, so here comes the problem part : while reading the value from DB the output shows like
"?PNG\r\n\n\0\0\0\rIHDR\0\0?\0\0?\b\0\0\0???(\0\0\0\tpHYs\0\0\v\0\0\v\0??\0\0\nOiCCPPhotoshop ICC profile\0\0x?SgTS?
Today its been 3 days since i am stuck at this silly problem , i hope ..
anyone with a solution to this problem or a whole new approach is really appreciable. [Only part i cant change is the PHP code]