You are here: Foswiki>Tasks Web>Item12703 (08 Jan 2014, MichaelDaum)Edit Attach

Item12703: Attached file will be destroyed when uploading... but when usind upload inside wikieditor the file isn't corrupted

pencil
Priority: Normal
Current State: Closed
Released In: n/a
Target Release: n/a
Applies To: Extension
Component: TopicInteractionPlugin
Branches: trunk
Reported By: RonnyLangrock
Waiting For:
Last Change By: MichaelDaum
Attached files will be destroyed when using "Manage Attachments" (.../foswiki/bin/attach/Main/...) but when usind upload inside wikieditor the file isn't corrupted

-- RonnyLangrock - 20 Dec 2013

Could you describe a bit more exactly how to recreate the issue?

Thanks.

-- GeorgeClark - 20 Dec 2013

Okay i will try...

I'm using foswiki 1.1.9 (upgraded from 1.1.8) running on a Windows 2003 server with Apache 2.4.6, PHP 5.4.22 and ActiveState Perl 5.16.3.1603.

The following Plug-Ins are installed:


Now i've two options to attach files to my articles. I can use the build-in function inside the wikieditor or i can use directly the option in the menu in the end of each article (Edit: Attach files and images). If i use the second option, the files i'm trying to attach will be destroyed (in my case *.pdf) but when i use the upload option inside the wikieditor the files are okay.

-- RonnyLangrock - 06 Jan 2014

Hi Ronny. What's your SKIN setting? Did you enable the UI part of TopicInteractionPlugin as described here? Note that TopicInteractionPlugin uses a different backend (not /foswiki/bin/attach) to upload files...

Any example pdf to test with?

-- MichaelDaum - 06 Jan 2014

Hey Michael,

my actual Skin Settings are the following:

Set SKIN = metacomment, nat Set DISPLAYCOMMENTS = on Set COMMENTFORMAT = insidetab Set NATSKIN_SIDEBAR = right Set NATSKIN_MENU = on Set NATSKIN_LAYOUT = bordered

If tried: Set SKIN = topicinteraction, metacomment, nat Set DISPLAYCOMMENTS = on Set COMMENTFORMAT = insidetab Set NATSKIN_SIDEBAR = right Set NATSKIN_MENU = on Set NATSKIN_LAYOUT = bordered after your advise, but when i'm running this settings no attachment is shown and it has the same affect on files while uploading them...

You can try any pdf, they aren't special ones wink

-- RonnyLangrock - 06 Jan 2014

Just SKIN = nat is sufficient. The other prefixes (metacomment, topicinteraction, etc) are only required for PatternSkin.

But that put aside, I wonder which "Manage Attachments" dialog you are using. Have you got a screenshot of it?

-- MichaelDaum - 06 Jan 2014

It would also be good to understand in what way the pdf is corrupted. Is it truncated, completely unreadable, wrong file attached, incorrectly encoded, uploaded as text vs. binary? There are a lot of things that can go wrong.

What is your locale / character set configured as? (Please get the following from lib/LocalSite.cfg)
$Foswiki::cfg{UseLocale} = ;
$Foswiki::cfg{Site}{Locale} = ;
$Foswiki::cfg{Site}{CharSet} = ;

-- GeorgeClark - 06 Jan 2014

I added some Screenshots...
  • 005 - show the menu point
  • 006 - "Manage Attachments" dialog
  • 007 - Error Message (File was correct before uploading!)

Actual configuration:
$Foswiki::cfg{UseLocale} = 0;
$Foswiki::cfg{Site}{Locale} = 'en_US.ISO-8859-1';
$Foswiki::cfg{Site}{CharSet} = 'iso-8859-1';

-- RonnyLangrock - 07 Jan 2014

Which browser did you use to upload the PDF?

What's the file-system underneath your Foswiki? Oh I see you've installed it under Windows.

Can you reproduce the error on http://demo.michaeldaumconsulting.com?

I've assigned the error to the TopicInteractionPlugin installed on your setup.

Unfortunately I can't reproduce the error as I never use a Windows machine for Foswiki. I'd strongly recommend to install Foswiki on a Linux machine.

Windows is:

  1. highly untested running Foswiki
  2. is a nightmare of its own running perl under utf-8
  3. more expensive to set up
  4. harder to maintain long term
  5. is no 24/7 operating system showing lower average uptime rates
  6. more vulnerable to security breaches
  7. delivering a slower performance
  8. requiring more expensive hardware
  9. not feature-equivalent with a comparable Linux install

So why should you do this? The only reason people still use Windows as a server operating system is:

  1. politics

-- MichaelDaum - 07 Jan 2014

Normally I use the latest Firefox, but i've also tried IE and Chrome. I cannot reproduce the error on your page. I'm in the same opinion, which belongs to server operating systems, but i'm in a corporate infrastructure, where i have to use a windows server :-/ (if i could choose my prefered server system i would use debian like in private, but i'm not allowed to)

-- RonnyLangrock - 07 Jan 2014

Not sure how I could help you on this one without being able to repro it.

-- MichaelDaum - 07 Jan 2014

Have a look at utf-8_demo.zip it contains an utf-8 demo text file, which i used to test.

when i upload the *.txt file it remains the same, but when i rename the same file to *.pdf and upload this, i have the effect that the file isn't the same any more... but have a look at your self when you open them with i.e. notepad++.

-- RonnyLangrock - 07 Jan 2014

The files in the attached zip have all different line-end encoding, which is a common problem under Windows.

  • UTF-8-demo.txt: UTF-8 Unicode English text
  • UTF-8-demo.txt.after_upload.pdf: UTF-8 Unicode English text, with CRLF, CR line terminators
  • UTF-8-demo.txt.before_upload.pdf: UTF-8 Unicode English text, with CRLF line terminators

It seems to be changing encoding as part of the upload. Below patch forces the file handler into binary mode. Have a try and let me know so that I can push out a new release:

--- lib/Foswiki/Plugins/TopicInteractionPlugin/Action/UploadAttachment.pm       (revision 17216)
+++ lib/Foswiki/Plugins/TopicInteractionPlugin/Action/UploadAttachment.pm       (working copy)
@@ -84,7 +84,7 @@
     appendFile($tmpFileName, $data);
   } else {
     Foswiki::Plugins::TopicInteractionPlugin::Core::writeDebug("saving to $tmpFileName");
-    Foswiki::Func::saveFile($tmpFileName, $data);
+    saveFile($tmpFileName, $data);
   }
 
   # end of transaction
@@ -171,7 +171,20 @@
   unless (open($FILE, '>>', $name)) {
     die "Can't append to $name - $!\n";
   }
+  binmode($FILE);
   print $FILE $text;
   close($FILE);
 }
+
+sub saveFile {
+  my ($name, $text) = @_;
+  my $FILE;
+  unless (open($FILE, '>', $name)) {
+    die "Can't create file $name - $!\n";
+  }
+  binmode($FILE);
+  print $FILE $text;
+  close($FILE);
+}
+

-- MichaelDaum - 08 Jan 2014

I can confirm that it now works smile

-- RonnyLangrock - 08 Jan 2014

Fix released in v3.43

-- MichaelDaum - 08 Jan 2014
 

ItemTemplate edit

Summary Attached file will be destroyed when uploading... but when usind upload inside wikieditor the file isn't corrupted
ReportedBy RonnyLangrock
Codebase 1.1.9
SVN Range
AppliesTo Extension
Component TopicInteractionPlugin
Priority Normal
CurrentState Closed
WaitingFor
Checkins TopicInteractionPlugin:43bd91c61827
TargetRelease n/a
ReleasedIn n/a
CheckinsOnBranches trunk
trunkCheckins TopicInteractionPlugin:43bd91c61827
Release01x01Checkins
I Attachment Action Size Date Who Comment
FireShot_Screen_Capture_005.pngpng FireShot_Screen_Capture_005.png manage 110 K 07 Jan 2014 - 10:20 RonnyLangrock  
FireShot_Screen_Capture_006.pngpng FireShot_Screen_Capture_006.png manage 100 K 07 Jan 2014 - 10:20 RonnyLangrock  
FireShot_Screen_Capture_007.pngpng FireShot_Screen_Capture_007.png manage 38 K 07 Jan 2014 - 10:20 RonnyLangrock  
utf-8_demo.zipzip utf-8_demo.zip manage 17 K 07 Jan 2014 - 17:49 RonnyLangrock  
Topic revision: r16 - 08 Jan 2014, MichaelDaum
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy