When I work in basic node, I can easily get a file and save it on my server :
let fs = require( 'fs' );
let https = require( 'https' );
var file = fs.createWriteStream( process.env.PWD + fileName );
let request = https.get( fileURL, function ( response ) {
response.pipe( file );
} );
But when I try to use Meteor HTTP, I cannot find how the content is encoded :
let file = HTTP.get( fileURL );
fs.writeFileSync(
process.env.PWD + '/imports/' + fileName,
new Buffer( file.content, 'utf8' )
);
I tried binary
, usc2
and other friends…
For a jpeg, the content looks like that :
���\u0000\u0018Exif\u0000\u0000II*\u0000\b\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000��\u0000\u0011Ducky\u0000\u0001\u0000\u0004\u0000\u0000\u0000<\u0000\u0000��\u00031http://ns.adobe.com/xap/1.0/\u0000<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?> <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.6-c111 79.158325, 2015/09/10-01:10:20 "> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/" xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#" xmp:CreatorTool="Adobe Photoshop CC 2015 (Macintosh)" xmpMM:InstanceID="xmp.iid:F0133203CE5511E5A010FA2CA91463FD" xmpMM:DocumentID="xmp.did:F0133204CE5511E5A010FA2CA91463FD"> <xmpMM:DerivedFrom stRef:instanceID="xmp.iid:F0133201CE5511E5A010FA2CA91463FD" stRef:documentID="xmp.did:F0133202CE5511E5A010FA2CA91463FD"/> </rdf:Description> </rdf:RDF> </x:xmpmeta> <?xpacket end="r"?>��\u0000\u000eAdobe\u0000d�\u0000\u0000\u0000\u0001��\u0000,.........
For All the text based file (json, xml…) it works well.
What did I miss ?