How to recognize file from ASP.NET MVC from chrome?
chrome' uploaded file come in octet format without name so if i save those file in common format then what effect file got.
fist thing is that i want to convert all those file in png [all uploaded content if GIF OR JPEG] so if i save them alredy in PNG then what effect file got.
any clue to handle this file who come without name.
are their any way to check that file are really image or not anything else.
What thin开发者_JAVA技巧gs i need to use to check and give them default name before saving them on virtual server.
are their any way to check that file are really image or not anything else.
You could apply heuristics and look at the first few bytes and try to recognize common image formats. Also you could try the following:
try
{
using (var img = Image.FromStream(someFileStream))
{
if (img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Png))
{
// it's a png
}
else if (img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg))
{
// it's a jpeg
}
...
}
}
catch (Exception ex)
{
// ... it's probably not an image format that can be handled
}
精彩评论