Answer the question
In order to leave comments, you need to log in
How to download a picture from the Internet and send it to dropbox?
Good afternoon. I am writing a simple application for downloading pictures from the Internet and sending them to dropbox. Here is the code:
let body = '';
request
.get('https://www.w3schools.com/css/img_fjords.jpg')
.on('data', chunk => {
body += chunk;
})
.on('end', () => {
console.log(typeof body);
let contents = new Buffer(body, null);
dbx.filesUpload({ path: '/w3.jpg', contents })
.then(resp => {
console.log(resp);
})
.catch(err => {
console.log(err);
});
})
.on('error', err => {
console.log('Error: ', err);
})
Answer the question
In order to leave comments, you need to log in
// если указать encoding:null - request вернет body в бинарном формате
request(
{url:'https://www.w3schools.com/css/img_fjords.jpg', encoding:null},
function (err, res, body) {
if(err) {
return console.error('error', err)
}
dbx.filesUpload({ path: '/w3.jpg', contents: body })
.then(resp => {
console.log(resp);
})
.catch(err => {
console.log(err);
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question