Tags:
create new tag
view all tags

Question

Whenever we open an attachment that's an Excel 2007 file (xlsx), we get the following error:

"Excel found unreadable content in [ATTACHMENT]. Do you want to recover the contents of this workbook?"

I tried adding new MIME types in the mime.types file under twiki/data, but that didn't work. I checked our TWiki configuration file and it is looking at that file for MIME types, rather than at an Apache mime.types file.

Not sure if there could be another cause to this problem, but I'm stuck at the moment so any help would be greatly appreciated.I haven't checked whether the same problem applies to docx or other Office 2007 file formats.

Environment

TWiki version: TWikiRelease04x02x00
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS:  
Web server: Apache 2.2.3
Perl version:  
Client OS: Windows XP
Web Browser: Firefox 3.0
Categories: Browser Issue

-- GarySprague - 08 Nov 2008

Answer

ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.

I just did some additional testing and confirmed that the same problem applies to docx files, so it seems to be a general problem with the Office 2007 file formats as opposed to an Excel-specific issue.

-- GarySprague - 10 Nov 2008

This seems to be an issue with Office 2007 MIME types and apache webserver.

If you are using Apache, just try to add following in apache's configuration file (/etc/httpd/conf/httpd.conf) and restart the webserver. That should fix this issue.

AddType application/vnd.ms-word.document.macroEnabled.12 .docm
AddType application/vnd.openxmlformats-officedocument.wordprocessingml.document docx
AddType application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx
AddType application/vnd.ms-powerpoint.template.macroEnabled.12 potm
AddType application/vnd.openxmlformats-officedocument.presentationml.template potx
AddType application/vnd.ms-powerpoint.addin.macroEnabled.12 ppam
AddType application/vnd.ms-powerpoint.slideshow.macroEnabled.12 ppsm
AddType application/vnd.openxmlformats-officedocument.presentationml.slideshow ppsx
AddType application/vnd.ms-powerpoint.presentation.macroEnabled.12 pptm
AddType application/vnd.openxmlformats-officedocument.presentationml.presentation pptx
AddType application/vnd.ms-excel.addin.macroEnabled.12 xlam
AddType application/vnd.ms-excel.sheet.binary.macroEnabled.12 xlsb
AddType application/vnd.ms-excel.sheet.macroEnabled.12 xlsm
AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
AddType application/vnd.ms-excel.template.macroEnabled.12 xltm
AddType application/vnd.openxmlformats-officedocument.spreadsheetml.template xltx
 

If you want to know more information - visit http://www.vladville.com/2007/04/office-2007-mime-types-for-apache.html

-- SopanShewale - 11 Nov 2008

Hi Sopan,

I've tried using the AddType directive in HTTPD for the docx, xlsx and pptx file types, but without luck. And as I said before, I don't believe TWiki is looking to Apache to determine the correct MIME types, rather it is looking at the mime.types file in the twiki/data directory.

In addition, most web pages I found referencing the MIME type problem indicated that the file would get downloaded as a ZIP or as a garbled application/octet-stream file type, neither of which is the case here. The files download as .xlsx, .docx, etc., it's just that upon opening them, MS Office seems to think they are somehow corrupted.

For reference, here is the HTTP header block from downloading an .xlsx attachment from our site:

http://twiki/twiki/bin/viewfile/Sandbox/ParentalTest?rev=1;filename=TestFile%283%29.xlsx

GET /twiki/bin/viewfile/Sandbox/ParentalTest?rev=1;filename=TestFile%283%29.xlsx HTTP/1.1 Host: twiki User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://twiki/twiki/bin/view/Sandbox/ParentalTest Cookie: TWIKIPREF=%7CTwistyContrib_topicattachmentslist%3D1; TWIKISID=18e05fb4447007091ed4be35a07ea362

HTTP/1.x 200 OK Date: Tue, 11 Nov 2008 22:14:24 GMT Server: Apache/2.2.3 (CentOS) content-disposition: inline;filename=TestFile(3).xlsx Content-Length: 13142 Connection: close Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

-- GarySprague - 11 Nov 2008

I also thought it might be helpful to show the details of the error message given by Excel upon opening the supposedly corrupt .xlsx file:

  <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
- <recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  <logFileName>error029640_02.xml</logFileName> 
  <summary>Errors were detected in file 'C:\DOCUME~1\GARY~1.SPR\LOCALS~1\Temp\TestFile(3).xlsx'</summary> 
- <additionalInfo>
  <info>Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded.</info> 
  </additionalInfo>
  </recoveryLog>

-- GarySprague - 11 Nov 2008

Yes, this is issue with TWiki. I will raise the bug after exploring possible place to fix in the code

The attachments can be viewed two ways in TWiki.

  • One way is use %ATTACHURL% - this expands to TWIKI_HOST_URL/twiki/pub/WEBNAME/TOPICNAME/FILENAME.ext (this works fine, because only webserver plays role here for delivery) and
  • other way is use URL as TWIKI_HOST_URL/twiki/bin/viewfile/WEBNAME/TOPICNAME?rev=1;filename=FILENAME.ext, this has a problem.

-- SopanShewale - 12 Nov 2008

Hi Sopan,

Thanks for your help with this. Just to give some context, I switched our attachment table link format from the standard ATTACHURL format to the "viewfile plus URL parameters" type because we were having browser caching issues with the standard format. After uploading a new version of an attachment, we would still get the previous version when clicking the link in the attachments table.

I tried using the ExpireActive and ExpiresDefault directives in our HTTPD files and in .htaccess files (with ExpiresActive set to "On" and ExpiresDefault set to "access"), but for some reason that didn't eliminate the caching issue.

-- GarySprague - 12 Nov 2008

Hi GarySprague, Its nice interacting you smile

I have raised the Bug - have a look at http://develop.twiki.org/~twiki4/cgi-bin/view/Bugs/Item6124 Looking forward to fix that.

-- SopanShewale - 13 Nov 2008

Hi Sopan,

Thanks for raising the bug! I really appreciate you taking the time to investigate this issue and bring it to the attention of the developer community. I also look forward to the fix! smile In the meantime, I've warned our users to upload in 97-2003 file formats only.

-- GarySprague - 14 Nov 2008

Hi GraySprague,

This issue does not appear in the recent trunk code from Subversion. You just need to update TWiki's mime.types file to include the Office2007 MIME types

If you do not want to upgrade to trunk's latest code, the fix for you would be:

[1] Add following content to your TWIKI_ROOT/data/mime.types file.

application/vnd.openxmlformats-officedocument.wordprocessingml.document docx
application/vnd.ms-word.document.macroEnabled.12 .docm
application/vnd.openxmlformats-officedocument.wordprocessingml.document docx
application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx
application/vnd.ms-powerpoint.template.macroEnabled.12 potm
application/vnd.openxmlformats-officedocument.presentationml.template potx
application/vnd.ms-powerpoint.addin.macroEnabled.12 ppam
application/vnd.ms-powerpoint.slideshow.macroEnabled.12 ppsm
application/vnd.openxmlformats-officedocument.presentationml.slideshow ppsx
application/vnd.ms-powerpoint.presentation.macroEnabled.12 pptm
application/vnd.openxmlformats-officedocument.presentationml.presentation pptx
application/vnd.ms-excel.addin.macroEnabled.12 xlam
application/vnd.ms-excel.sheet.binary.macroEnabled.12 xlsb
application/vnd.ms-excel.sheet.macroEnabled.12 xlsm
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
application/vnd.ms-excel.template.macroEnabled.12 xltm
application/vnd.openxmlformats-officedocument.spreadsheetml.template xltx
[2]. Modify the code TWIKI_ROOT/lib/TWiki/UI/View.pm from

   my $type = _suffixToMimeType( $session, $fileName );
    my $length =  length( $fileContent );
    my $dispo = 'inline;filename='.$fileName;

    print <<HERE;
Content-type: $type
Content-length: $length
Content-Disposition: $dispo

$fileContent
HERE
}

to

   my $type = _suffixToMimeType( $session, $fileName );
    my $length =  length( $fileContent );
    my $dispo = 'inline;filename='.$fileName;
    print $query->header("-type"=>$type, "-Content-length"=>$length, "-Content-Disposition"=>$dispo,);
    print $fileContent;
}

I assume the answer is satisfactory-closing this question now.

-- SopanShewale - 16 Nov 2008

Hi Sopan,

Sorry for not responding sooner. I forgot to subscribe to this topic, and I just now checked it and saw your post from Nov 16. I made the changes to Mime.Types and View.pm and they worked perfectly. Everything appears to be downloading error-free now. Thanks so much for all your help!

-- GarySprague - 04 Dec 2008

Hmmm. I'm having the update problem in Firefox 9.0 on Fedora Linux x86_64.

My View.pm file contains:

    my $dispo = 'inline;filename='.$fileName;

    $session->{response}->header(-type => $type, qq(Content-Disposition="$dispo") );
    $session->{response}->body($fileContent);

At first glance, this differs from the suggested change in two ways.

  1. There is no dash in front of Content-Disposition.
  2. There is no Content-Length parameter.

-- SteveKelem - 2012-01-23

On leading dashes see http://stackoverflow.com/questions/4511568/why-does-the-perl-cgi-module-use-hyphens-to-start-named-arguments

On content-length try adding: "-Content-length"=>$length, after -type => $type,

-- PeterThoeny - 2012-01-24

Change status to:
Edit | Attach | Watch | Print version | History: r13 < r12 < r11 < r10 < r9 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r13 - 2012-01-24 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.