Downloaded (image) file is different from received file
The description here, for receiving an attachment, works well, but when I try it with an image I get the following problem. The original (jpg) file looks like this in a text editor: \377\330\377\340^@^PJFIF^@^A ..... but the file, after being received and then uploaded (to Amazon S3) looks like this: \375\375\375\375^@^PJFIF^@^A ..... So all of the escape sequences have been converted to this \375 sequence. Is it obvious why that would be happening? Here's what I'm doing:
request({ url: attachment.contentUrl, headers:{ 'Authorization' : 'Bearer ' + connector.accessToken, 'Content-Type': 'application/octet-stream' } }, function (error, response, body){ const Buff = Buffer.from(body,'binary'); var s3Params = { Bucket: ..., Key: ...., Body: Buff, ACT: .... };
s3.putObject(s3Params,function(s3err,s3res){
stuff
});
});
Writing to S3 has worked before, so I don't think that's the problem. I just can't figure out why the files would be identical other than those escape sequences, and was wondering if someone recognizes this.
In case this helps, if anyone is looking at this comment.
You can ignore all of the stuff about Amazon S3. I have used fs to write the "body" directly to the local file system. When I examine that file, and the original file, they are not the same (in the way described above.)
So, in summary:
- I upload a file [FILE] to the Skype Bot
- I use the resulting content URL to request that file as an octet-stream
- I write the resulting response.body to a local file [NEW FILE]
If I compare [FILE] and [NEW FILE], they are not the same. I am sure I'm doing something obviously wrong, but I can't find it.
Wow. So I stumbled across the answer. I have no idea how someone is supposed to figure this out, but someone did. Although I'm happy to see that they thought it was as crazy as I do. http://stackoverflow.com/questions/14855015/getting-binary-content-in-node-js-using-request