Downloading excell works in dev mode but fails in prod mode

197 views
Skip to first unread message

Deepak Singh

unread,
May 26, 2013, 2:56:45 PM5/26/13
to google-a...@googlegroups.com
Hi,

I am downloading an excell sheet with following headers

downloadServlet.java

{

byte[] fileToSend = baos.toByteArray();
res.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
res.setContentLength(fileToSend.length);
res.getOutputStream().flush();
res.setCharacterEncoding("UTF-8");
res.setHeader("CacheControl", "no-cache");
res.setHeader("Pragma", "no-cache");
res.setHeader("Expires", "-1");
res.setHeader("Content-disposition", "attachment; filename=hotel.xls");
res.getOutputStream().write(fileToSend);

}

it works fine dev mode and am able to download and see content with file name as hotel.xls.

But when deployed to app engeine server, it downloads file named downloadServlet.xlsx instead of hotel.xls. because of the file type difference (xlsx instead of xls), i am not able to open the file correctly and see the content.

Can somebody suggest why this file type difference happens after deployment ?


 
Deepak Singh

Deepak Singh

unread,
May 28, 2013, 12:13:40 PM5/28/13
to google-a...@googlegroups.com
Can anyone pls suggest whats wrong here...
--
Deepak Singh

Vinny P

unread,
May 28, 2013, 1:57:34 PM5/28/13
to google-a...@googlegroups.com
Hello,

On Sunday, May 26, 2013 1:56:45 PM UTC-5, Deepak Singh wrote:
But when deployed to app engeine server, it downloads file named downloadServlet.xlsx instead of hotel.xls. because of the file type difference (xlsx instead of xls), i am not able to open the file correctly and see the content.


Yes, this is the proper behavior. App Engine production and your browser are working correctly. 

The problem is that your code is specifying the wrong MIME type. You claim that the file is a .XLS file (which has the MIME type of " application/vnd.ms-excel " ) but your code is claiming a MIME type of " application/vnd.openxmlformats-officedocument.spreadsheetml.sheet " (wow, that's a mouthful!) which is the type reserved for Excel Open XML format (in other words, .XLSX). You need to change this line: res.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); to instead set a MIME type of " application/vnd.ms-excel ".

Short version:
.XLS has a MIME type of application/vnd.ms-excel "
.XLSX has a MIME type of application/vnd.openxmlformats-officedocument.spreadsheetml.sheet "


-----------------
-Vinny P
Technology & Media Advisor
Chicago, IL

My Go side project: http://invalidmail.com/

Thiago Catoto

unread,
May 28, 2013, 5:08:12 PM5/28/13
to google-a...@googlegroups.com
+1 Vinny


--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages