You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Daniel Blumenthal <da...@wordchamp.com> on 2006/10/30 07:24:30 UTC

Internet Explorer and serving files

I'm trying to get my server to send an MP3 file to the client, but it's just
not working on Internet Explorer (Firefox works fine).  The user clicks a
link like this:
 
<a href="/myapp/GetMP3.do?id=1">download file</a>
 
And whereas Firefox opens up a "save as" window, IE forwards you to an error
404.  I've read about IE mime-sniffing, but is there any solution?  (I've
also tried sub-classing DownloadAction, but to no avail)
 
The servlet code looks like:
 
response.reset();
response.setContentType("audio/x-mpeg");    // I've also tried
"application/x-download"
response.setContentLength((int)filelen);
response.setHeader("Content-Disposition","attachment; filename=foo.mp3");
 
BufferedInputStream in = new BufferedInputStream(...);
BufferedOutputStream out = new
BufferedOutputStream(response.getOutputStream());
 
int count;
byte buffer = new byte[1024];
while ((count = in.read(buffer,0,1024)) != -1)
      out.write(buffer,0,count);
 
out.flush();
out.close();
response.flushBuffer();
 
 

Re: Internet Explorer and serving files

Posted by Ayusman Dikshit <ma...@gmail.com>.
try this on IE:
<a target="_blank" href="/myapp/GetMP3.do?id=1"
>
> >download file</a>


the content type seems fine.

Hope this works.
Regards
Ayusman



On 10/30/06, Daniel Blumenthal <da...@wordchamp.com> wrote:
>
> I'm trying to get my server to send an MP3 file to the client, but it's
> just
> not working on Internet Explorer (Firefox works fine).  The user clicks a
> link like this:
>
> <a href="/myapp/GetMP3.do?id=1">download file</a>
>
> And whereas Firefox opens up a "save as" window, IE forwards you to an
> error
> 404.  I've read about IE mime-sniffing, but is there any solution?  (I've
> also tried sub-classing DownloadAction, but to no avail)
>
> The servlet code looks like:
>
> response.reset();
> response.setContentType("audio/x-mpeg");    // I've also tried
> "application/x-download"
> response.setContentLength((int)filelen);
> response.setHeader("Content-Disposition","attachment; filename=foo.mp3");
>
> BufferedInputStream in = new BufferedInputStream(...);
> BufferedOutputStream out = new
> BufferedOutputStream(response.getOutputStream());
>
> int count;
> byte buffer = new byte[1024];
> while ((count = in.read(buffer,0,1024)) != -1)
>       out.write(buffer,0,count);
>
> out.flush();
> out.close();
> response.flushBuffer();
>
>
>
>


-- 
TIA,
Ayusman