У меня есть следующий код, который по сути "передает" файл с одного сервера на другой. Он отлично работает в IE, но Firefox, похоже, игнорирует заголовок Content-Type
и всегда передает файлы (MP3) как text/html
.
Это не главная проблема, но я бы хотел, чтобы она работала корректно во всех браузерах, так может кто-нибудь помочь? Кроме того, если есть лучший / более эффективный способ сделать это, пожалуйста, напишите об этом!
FileInfo audioFileInfo = new FileInfo(audioFile);
HttpWebRequest downloadRequest = (HttpWebRequest) WebRequest.Create(audioFile);
byte[] fileBytes;
using (HttpWebResponse remoteResponse = (HttpWebResponse) downloadRequest.GetResponse())
{
using (BufferedStream responseStream = new BufferedStream(remoteResponse.GetResponseStream()))
{
fileBytes = new byte[remoteResponse.ContentLength];
responseStream.Read(fileBytes, 0, fileBytes.Length);
Response.ClearContent();
// firefox seems to ignore this...
Response.ContentType = Utilities.GetContentType(audioFileInfo);
// ... and this
//Response.ContentType = remoteResponse.ContentType;
Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", audioFileInfo.Name));
Response.AddHeader("Content-Length", remoteResponse.ContentLength.ToString());
Response.BinaryWrite(fileBytes);
Response.End();
}
}