问题描述:

I am fighting with currently with nodejs, trying to download images from evernote via the api.

noteStore.getResourceData(guid, function (err, res) {

console.log(res.length);

});

my problem with this code is, in my console I can see the the length of the file, but as soon I try to use the value somewhere else, or save the file, I hit problems.

var l = res.length;

^

Cannot read property 'length' of undefined

any ideas how to fix this?

What I wont is to save the file, but I hitting the same problem when I use this:

var wstream = fs.createWriteStream(guid + '.' + type);

wstream.write(res);

网友答案:

Ok, so far there is no solution for this in the internet, I found a way to handle the image download and saving:

noteStore.getResourceData(guid, function (err, res) {
            try{
                var buffer = new Buffer(res);

                var wstream = fs.createWriteStream(guid + '.' + type, {'flags': 'w', encoding: 'binary'});
                wstream.write(buffer, encoding='binary', function(err) {

                });

            } catch(e) {
                console.log(e);
            }
});
相关阅读:
Top