我通过下载图像request,然后通过 处理图像sharp。但是有一个错误,输入文件丢失,实际上变量body有一个值。
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( …Run Code Online (Sandbox Code Playgroud)