scan files programatically when uploading via asp.net mvc
We are using HttpPostedFileBase to upload files to our asp.net mvc application. Is there some smart way of 开发者_如何学Pythonanalyzing the contents of the file to determine the actual mime type by looking at the actual binary stream?
I want to make sure no .exe files or similar stuff are uploaded, just want to accept a number of files.
Something like a preflight on the file that is uploaded to extract information programmatically and determine the file type.
postedFile.ContentType
You can use ContentType as stated by alfdev
but I would like you to be careful with this as the ContentType can be spoofed under certain cicumstances.
MIME types for uploaded files can be spoofed under some circumstances, so checking the file's MIME type alone is not a reliable security check.
Read this from MSDN.
This link can be used to understand the way by which you can check the content type of the file
精彩评论