gpt4 book ai didi

node.js - 严重错误 : [Error: Input file is missing]

转载 作者:行者123 更新时间:2023-12-04 01:32:40 24 4
gpt4 key购买 nike

我通过request下载图片,然后通过sharp处理图片.
但是出现输入文件丢失的错误,实际上是变量body有一个值(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) });
}
})
}
});
}

最佳答案

我在 sharp 上发现了一个问题概述解决方案的 repo :

the request module expects encoding to be set to receive body as a Buffer.


- request(url, function(error, response, body) {
+ request({ url, encoding: null }, function(error, response, body) {

来源: https://github.com/lovell/sharp/issues/930#issuecomment-326833522

关于node.js - 严重错误 : [Error: Input file is missing],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60613585/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com