I am having a problem submitting a UTF8 encoded text file in a POST request using NodeJS "shred"
The text content I am trying to post looks fine on the client side, I know because I console.log it to the screen just before calling client.post, what the server gets is the content of the text file but the last 2 chars are always missing/chopped. This is not a problem with ANSI text files. If I convert the textfile from UTF8 to ANSI, it is complete when it reaches the server.
var Shred = require('shred');
var client = new Shred();
var textToPost = fs.readFileSync("myfile.txt", 'utf8');
console.log (textToPost);
client.post({
url: "http://www.example.com/readTextFile.php",
headers: { 'Content-Type': 'application/x-subrip'},
content: textToPost,
on: {
200: function (response) {
console.log("posted ok");
console.log(response.content.body);
},
500: function (response) {
asyncCb(new Error('bad response\n' + response.content.body));
}
}
What is recieved on the server (by readTextFile.php) is the contents of myfile.txt with the last 2 chars stripped out. I cannot understand why. This has big downstream implications so any patchy workarounds are not likely to help.
I also noticed that when the contents of textToPost are logged to the console, there is a "?" preceding the contents. This doesn't appear when the file is an ANSI encoded file.
Please help.. thank you