为什么 iPhone/iPad 上的浏览​​器不能 download/preview docx 文件?

Why browsers on iPhone/iPad cannot download/preview docx files?

我的 Web 应用程序允许最终用户上传文档并将其存储在数据库中。他们也可以从应用程序下载该文档。

下载文档的行为很简单,用户在GUI上点击一个link "Download this document",我会根据请求的输入documentID参数从数据库中查询文档二进制数据客户端。之后,我会将字节数据响应给客户端。

让我们看看我的代码。

这是我接收客户端下载文档请求的函数。

Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
    Dim DocumentID As String = getParameter("DocumentID", context)
    DocumentWrapper.Download(DocumentID)
    context.Response.Write("<script language=javascript>window.open('','_self','');window.close();</script>")
End Sub

这就是我查询二进制数据并响应给客户端的功能。

 Public Shared Sub Download(ByVal documentId As String)
        Dim contentType As String = String.Empty
        Dim bytes As Byte() = Nothing
        Dim docItem As DocumentEntity = New DocumentEntity()

        If (documentId IsNot Nothing) Then
            docItem = New DocumentDao().SelectByDocumentID(documentId)

            If Not String.IsNullOrEmpty(docItem.auto_key.Trim()) Then
                HttpContext.Current.Response.Clear()
                HttpContext.Current.Response.ClearContent()
                HttpContext.Current.Response.ClearHeaders()
                HttpContext.Current.Response.ContentType = GetContentType(docItem.fileexten)
                HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" & docItem.filename.Trim & "." & docItem.fileexten.Trim)

                If (docItem.document IsNot Nothing) AndAlso (docItem.document IsNot System.DBNull.Value) Then
                    HttpContext.Current.Response.BinaryWrite(docItem.document)
                End If

                HttpContext.Current.Response.Flush()
                HttpContext.Current.Response.Close()
                HttpContext.Current.Response.End()
            End If
        End If
    End Sub
End Class

现在,我的用户从我的 Web 应用程序下载 docx 文件。

所以,我的问题是为什么 iPad/iPhone 上的浏览​​器无法下载 docx?有没有办法做到这一点?或者这是 iOS 为 iPad/iPhone 保护最终用户的预期行为?

我找到了这个问题的答案。只是 return docx 的正确 ContentType https://docs.microsoft.com/en-us/previous-versions/office/office-2007-resource-kit/ee309278(v=office.12)