<p>I am using a perl script to POST to Google Appengine application. I post a text file containing some XML using the -F option.</p>

<p><a href="http://www.cpan.org/authors/id/E/EL/ELIJAH/bget-1.1" rel="nofollow noreferrer">http://www.cpan.org/authors/id/E/EL/ELIJAH/bget-1.1</a></p>

<p>There is a version 1.2, already tested and get the same issue. The post looks something like this.</p>

<pre><code>Host: foo.appspot.com
User-Agent: lwp-request/1.38
Content-Type: text/plain
Content-Length: 202

&lt;XML&gt;
   &lt;BLAH&gt;Hello World&lt;/BLAH&gt;
&lt;/XML&gt;
</code></pre>

<p>I have modified the example so the 202 isn't right, don't worry about that. On to the problem. The Content-Length matches the number of bytes on the file, however unless I manually increase the Content-Length it does not send all of the file, a few bytes get truncated. The number of bytes truncated is not the same for files of different sizes. I used the -r option on the script and I can see what it is sending and it is sending all of the file, but Google Appengine self.request.body shows that not everything is received. I think the solution is to get the right number for Content-Length and apparently it isn't as simple as number of bytes on the file or the perl script is mangling it somehow.</p>

<p>Update:
Thanks to Erickson for the right answer. I used printf to append characters to the end of the file and it always truncated exactly the number of lines in the file. I suppose I could figure out what is being added by iterating through every character on the server side but not worth it. This wasn't even answered over on the google groups set up for app engine!</p>

[{'answer_id': 46405, 'author': 'erickson', 'author_id': 3474, 'author_profile': 'https://Stackoverflow.com/users/3474', 'pm_score': 3, 'selected': True, 'text': '<p>Is the number of extra bytes you need equal to the number of lines in the file? I ask because perhaps its possible that somehow carriage-returns are being introduced but not counted.</p>\n'}, {'answer_id': 46417, 'author': 'Jagmal', 'author_id': 4406, 'author_profile': 'https://Stackoverflow.com/users/4406', 'pm_score': 0, 'selected': False, 'text': '<p>How are you getting the number of bytes? .. By looking at the size of the file on the filesystem?</p>\n\n<p>You can use "-s" to get the size of the file.</p>\n\n<p>Or, if you want to do more, you may use <a href="http://search.cpan.org/~rgarcia/perl-5.10.0/lib/File/stat.pm" rel="nofollow noreferrer">File::Stat</a></p>\n'}, {'answer_id': 46551, 'author': 'shelfoo', 'author_id': 3444, 'author_profile': 'https://Stackoverflow.com/users/3444', 'pm_score': 1, 'selected': False, 'text': '<p>I\'ve run into similar problems before.</p>\n\n<p>I assume you\'re using the length() function to determine the size of the file? If so, it;s likely the data that you\'re posting is UTF-8 encoded, instead of ASCII.</p>\n\n<p>To get the correct count you may need to add a "use bytes;" pragma to the top of your script, or wrap the length call in a block:</p>\n\n<pre><code>my $size;\ndo {use bytes; $size = length($file_data)}\n</code></pre>\n\n<p>From the perlfunc man page:</p>\n\n<p>"Note the characters: if the EXPR is in Unicode, you will get the number of characters, not the number of bytes."</p>\n'}]
['https://Stackoverflow.com/questions/46387', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4527/']