0

我有电子商务网站并在其中上传了一些mp3文件,客户可以将mp3文件下载到PC上,但是当他们尝试将它们下载到iPad时,iPad无法下载它们。

下载文件的代码如下

public static void DownloadAudio(string url)
{
    if (HttpContext.Current.CurrentHandler is basePage)
    {

        HttpContext.Current.Response.Clear();
        string fileDiskPath = HttpContext.Current.Server.MapPath(url);
        FileInfo fileInfo = new FileInfo(fileDiskPath);

        HttpContext.Current.Response.ContentType = "audio/mp3";
        HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment;filename={0}", fileInfo.Name));
        HttpContext.Current.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
        HttpContext.Current.Response.WriteFile(fileDiskPath);
        //HttpContext.Current.Response.Flush();
        HttpContext.Current.Response.End();

    }
    else
    {
        throw new NotSupportedException("Note: This method is not supporting user controls.  Consider supporting user controls by getting the parent page from user control.");
    }
}
4

2 回答 2

1

iPad 上的 Safari 浏览器只允许用户下载他们安装了可以处理它的应用程序的文件——默认情况下,没有内置的 iOS 应用程序可以处理任意下载或 MP3 文件。

如果您的访问者安装了 GoodReader 之类的应用程序,则 Mobile Safari 将提示用户在 GoodReader 中打开下载。

于 2012-09-25T19:38:55.213 回答
0

尝试使用官方 MIME 类型。

HttpContext.Current.Response.ContentType = "audio/mpeg";
于 2012-09-25T19:38:39.647 回答