Works with 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();
Error with aws-sdk-js v3: I understand that is because originalPhoto
is not a Buffer.
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
The error: Input file is missing
ERROR Unhandled Promise Rejection
{"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"Error: Input file is missing",
Sharp version: 0.28.1
Try this: