开发者

scan files programatically when uploading via asp.net mvc

开发者 https://www.devze.com 2023-01-25 18:12 出处:网络
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 lo

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号