【发布时间】:2020-06-22 02:41:31
【问题描述】:
我通过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( err => { console.log('error', err) });
}
})
}
});
}
【问题讨论】:
-
我发现了一些可能有帮助的细节 - github.com/lovell/sharp/issues/930#issuecomment-326833522
-
这行得通吗?
-
@nopassport1 是的,