I am trying to succeed in uploading an image without associating it with fs. Here is what I did:
var Promise = require('bluebird'), fs = Promise.promisifyAll(require('fs')), requestAsync = Promise.promisify(require('request')); function downloadImage(uri, filename){ return requestAsync(uri) .spread(function (response, body) { if (response.statusCode != 200) return Promise.resolve(); return fs.writeFileAsync(filename, body); }) .then(function () { ... })
Valid input can be:
downloadImage('http://goo.gl/5FiLfb', 'c:\\thanks.jpg');
I really think the problem is with body processing. I tried to make it in Buffer ( new Buffer(body, 'binary') , etc.) In several encodings, but all failed.
Thanks for the help!
Selfish
source share