cancel
Showing results for 
Search instead for 
Did you mean: 

Issue on calculating uploaded document size

abarisone
Star Contributor
Star Contributor
Hi,
I experienced an issue when calculating uploaded document size, using this code snippet:

var contentError = false;
  var contentSize = 0;
  for each (field in formdata.fields) {
      if (field.isFile) {
          if (contentErrore == false) {
              filename = Decoder.decodeHTML //custom function to get filename
             contentSize = field.content.content.bytes.length;
              if (contentSize > 20971520)
                  contentError = true;
              else
                  content = field.content;
          }
      }
}
The problem is that on Windows the contentSize variable contains the real size of the document, whereas on Linux (RH 5.3) this value is about contentSize divided by 1.7.
This is very strange and I couldn't find any explanation.
Any help appreciated.

Andrea
2 REPLIES 2

afaust
Legendary Innovator
Legendary Innovator
Hello,

just for clarification: the difference is observed between a server running on Windows and a server running on Linux? Or is it between requests from different clients?

What is the transfer encoding being used in both cases? Also note, that you access the length of the stringified content using this type of access, which may be a problem for non-textual content (all binary format files, including Office / PDF formats). You should rather use
field.content.size
as this should not perform an implcit conversion.

Regards
Axel

abarisone
Star Contributor
Star Contributor
First of all, thanks for your prompt reply.
The code is the same and the difference is observed between a server running on Windows and a server running on Linux (either with Alfresco 3.3.g or 4.0.d).

Using
field.content.size
we always obtain -1 as result, no matter if the file is binary or text.

More precisely on Linux we obtain the correct value with a text file and a value/1.7 with a binary file.
Thanks,
Andrea