您好,夏普方法返回我的“无效输入”

发布于 2025-01-24 10:04:35 字数 738 浏览 2 评论 0原文

当我使用尖锐的功能时,我会得到“无效的输入”。 我知道这是

import { BadRequestException, Injectable, PipeTransform } from '@nestjs/common';
import * as path from 'path';
import * as sharp from 'sharp'

@Injectable()
export class SharpPipe implements PipeTransform<Express.Multer.File, Promise<string>> {

    async transform(image: Express.Multer.File): Promise<string> {
        const originalName = path.parse(image.originalname).name;
        const filename = Date.now() + '-' + originalName + '.webp';

           await sharp(image.buffer)
               .resize(800)
               .webp({effort: 3})
               .toFile(path.join('uploads', filename));

        return filename;
    }

}

一个问题是尖锐的方法。帮我

when i use sharp function, i get "Invalid Input". Here is the code

import { BadRequestException, Injectable, PipeTransform } from '@nestjs/common';
import * as path from 'path';
import * as sharp from 'sharp'

@Injectable()
export class SharpPipe implements PipeTransform<Express.Multer.File, Promise<string>> {

    async transform(image: Express.Multer.File): Promise<string> {
        const originalName = path.parse(image.originalname).name;
        const filename = Date.now() + '-' + originalName + '.webp';

           await sharp(image.buffer)
               .resize(800)
               .webp({effort: 3})
               .toFile(path.join('uploads', filename));

        return filename;
    }

}

i know that a problem is into sharp method. Help me guys

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把时间冻结 2025-01-31 10:04:35

缓冲区属性仅对您使用MemoryStorage对Multer有效。使用{存储:multer.memorystorage()}设置Multer Init选项可能会解决您的问题。

The buffer property is only valid on you are using the MemoryStorage for the multer. Set the multer init options with {storage:multer.MemoryStorage()} may fix your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文