MAC载流文件中确定MIME类型类型、文件、MAC、MIME

2023-09-03 01:49:52 作者:北城以念·何以为安

我发送一个简单的Web表单,并通过.NET C#发送电子邮件了。此外,还有从我创建了一个内存流和附加流的邮件...一个ASP上传CTRL即无需保存文件到文件系统。

I have a simple web form that sends and email out via .NET C#. Additionally there is an ASP UPLOAD ctrl from which I create a memory stream and attach the stream to the Mail Message...ie no need to save file to file system.

问题:当MAC用户不inlcude他们上传的文件扩展名(我测试的PostedFile.ContentType以确定文件和/或相应的扩展,允许文件RTF,TXT,PDF,DOC,DOCX)好像将contentType回来为应用程序/八位字节......这使得一些意义,我W / O所要求的个人电脑,但延长;目前还不清楚天气读的ContentType或扩展是一个更好的办法来确定它是什么类型的文件前附上。 [扩展名的Mac文件显然会失败的任何扩展测试]

ISSUE: When MAC users dont inlcude extensions on their uploaded files (I am testing for PostedFile.ContentType to determine the file and/or appropriate extension, allowable files RTF, TXT, PDF, DOC, DOCX) it seems like the ContentType comes back as "application/octet"...this makes some sense to me w/o an extension as required by PCs but; still unclear on weather reading the ContentType or extension is a better way to determine what type of file it is before I attach. [Extensionless MAC file will obviously fail any extension test]

基本上,我读了上传CTRL文件,确定它的ContentType是,带刚好PostedFile.Filename,然后重新组装,我创建一个使用的ContentType字符串中的一个switch语句来确定并添加正确的扩展附件附加的文件(文件名+分机)。我为了确保不使用扩展仍然可以上传W / O创造了.ZIP或其他包的MAC用户这样做。

Basically, I read the file from the upload ctrl, determine what its ContentType is, strip just the PostedFile.Filename and then reassemble as I create the attachment using the ContentType string in a switch statement to determine and add the correct extension to the attached file (filename + ext). I did this in order to ensure MAC users that dont use extensions can still upload w/o creating a .ZIP or other package.

问题1:我的逻辑的声音,关于处理这个问题,最好的做法是什么? 问题2:将所有的MAC文件恢复为应用程序/ octect当不使用Mac的延伸,如果是这样,怎么能一个人决定什么类型的文件,它真的是? (注:PDF正常工作时,不使用扩展的MAC平台)。

Question 1: Is my logic sound with regards to approaching this issue, best practices? Question 2: Will all MAC files return as "application/octect" when not using an extension on MAC, and if so, how can someone determine what type of file it really is? (Note: PDF worked fine when not using extensions on MAC platform).

在此先感谢。 如果code样品是必要的,请告知。

Thanks in advance. If code sample is necessary please advise.

推荐答案

不使用的文件扩展名摸出MIME类型,而是使用Winista二进制分析,看看我的方法在这里,诉诸回到URLMON如果winista着工作了最后的答案 http://social.msdn.microsoft.com/Forums/en-US/Vsex$p$pssvcs/thread/d79e76e3-b8c9-4fce-a97d-94ded18ea4dd

有人说重命名一个exe与JPG扩展......你还是可以判断真实的文件格式。它不会检测SWF的或FLV的,但确实pretty的任何地方都熟知的格式+你可以得到一个十六进制编辑器,并添加更多的文件它可以检测。的

编辑: 下载Winista: http://www.netomatix.com/Products/DocumentManagement/MimeDetector.aspx

Download Winista: http://www.netomatix.com/Products/DocumentManagement/MimeDetector.aspx

这个问题给了我一个伟大的想法,因为你想添加一个文件扩展名,将安全工作在Mac和PC I /您可以编辑的mime-的types.xml文件,包括安全的文件扩展名,将工作开在Mac和PC特定的文件类型。

This question has given me a great idea, since you wish to append a File Extension that will safely work on MACs and PCs I/you could edit the mime-types.xml file to include safe file extensions that will work to open specific file types on both MAC and PCs.