我正在尝试从文件内容中获取mime类型。在IIS Express和在Windows 10本地配置的IIS上运行良好,但是当我将应用程序发布到Windows 2012 Server时。 xlsx文件的Mime返回了application / octet-stream。
Public Shared Function GetMimeType(ByVal file As String) As String
Dim mime As String = Nothing
Dim MaxContent As Integer = CInt(New FileInfo(file).Length)
If MaxContent > 4096 Then
MaxContent = 4096
End If
Dim fs As New FileStream(file, FileMode.Open)
Dim buf(MaxContent) As Byte
fs.Read(buf, 0, MaxContent)
fs.Close()
Dim result As Integer = FindMimeFromData(IntPtr.Zero, file, buf, MaxContent, Nothing, 0, mime, 0)
Return mime
End Function
<DllImport("urlmon.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True,
SetLastError:=False)>
Private Shared Function FindMimeFromData(
ByVal pBC As IntPtr,
<MarshalAs(UnmanagedType.LPWStr)>
ByVal pwzUrl As String,
<MarshalAs(UnmanagedType.LPArray, ArraySubType:=UnmanagedType.I1, SizeParamIndex:=3)> ByVal _
pBuffer As Byte(),
ByVal cbSize As Integer,
<MarshalAs(UnmanagedType.LPWStr)>
ByVal pwzMimeProposed As String,
ByVal dwMimeFlags As Integer,
<MarshalAs(UnmanagedType.LPWStr)>
ByRef ppwzMimeOut As String,
ByVal dwReserved As Integer) As Integer
End Function
我希望将文件xlsx输出为application/vnd.openxmlformats-officedocument.spreadsheetml.sheet