2012-09-25 76 views
0

我有電子商務網站並上傳了一些mp3文件,客戶可以將mp3文件下載到電腦上,但是當他們嘗試將它們下載到iPad時,iPad無法下載它們。爲什麼iPad不能下載mp3文件?

下載文件的代碼如下

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."); 
    } 
} 
+2

那麼...... iPad上的用戶試圖下載mp3會發生什麼? – Gromer

+0

消息出現說「Safari瀏覽器無法下載文件」 –

回答

0

嘗試使用官方的MIME類型。

HttpContext.Current.Response.ContentType = "audio/mpeg"; 
+0

我已經試過這個,但它也失敗了 –

1

iPad上的Safari瀏覽器只會讓用戶下載他們有一個安裝應用程序,它可以處理一個文件 - 在默認情況下沒有內置的iOS應用程序將處理任意下載或MP3文件。

如果您的訪問者安裝了GoodReader等應用程序,Mobile Safari會提示用戶在GoodReader中打開下載。

+0

但我嘗試從另一個網站下載mp3文件並且下載操作成功,所以我無法確定問題到底在哪裏 –