I download the image through request
, and then process the image through sharp
.
But there is an error that input file is missing, actually the variable body
has a value.
import { IADLandingPageABTest } from '@byted/ec-types';
import request from 'request';
import sharp from 'sharp';
const images: Array<keyof IADLandingPageABTest> = ['topPosterUrl', 'bottomPosterUrl'];
export default function handleImage (config: IADLandingPageABTest) {
images.forEach(key => {
const url = config[key];
if (url && typeof url === 'string' ) {
request(url, (err, response, body) => {
//console.log('body', body);
//body has a value
if (!err && response.statusCode === 200) {
sharp(body)
.resize(100)
.toBuffer()
.then((data) => {
console.log(data.toString('base64'));
})
.catch( err => { console.log('error', err) });
}
})
}
});
}