适用于 aws-sdk-js v2:
const Sharp = require('sharp');
const AWS = require('aws-sdk');
const S3 = new AWS.S3({ signatureVersion: 'v4' });
const originalPhoto = (await S3.getObject({ Bucket: "myBucket", Key: "myKey" }).promise()).Body;
const originalPhotoDimensions = await Sharp(originalPhoto).metadata();
aws-sdk-js v3 出错:我知道那是因为originalPhoto
它不是缓冲区。
const Sharp = require('sharp');
const { S3Client, GetObjectCommand } = require("@aws-sdk/client-s3");
const S3 = new S3Client({ region: "us-east-1" });
const originalPhoto = (await S3.send(new GetObjectCommand({ Bucket: "myBucket", Key: "myKey" }))).Body;
const originalPhotoDimensions = await Sharp(originalPhoto).metadata(); // <--- Error
错误:输入文件丢失
ERROR Unhandled Promise Rejection
{"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"Error: Input file is missing",
夏普版本: 0.28.1