小编gee*_*ine的帖子

严重错误:[错误:输入文件丢失]

我通过下载图像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)

request node.js sharp

8
推荐指数
2
解决办法
2万
查看次数

标签 统计

node.js ×1

request ×1

sharp ×1