I’m looking for the correct way to read a PNG from S3 and send it to the openai API.
Given:
const command = new GetObjectCommand({
Bucket: BUCKET,
Key: `library/${sourceId}.png`
});
const result = await s3.send(command);
const stream = Readable.from(result.Body);
const response = await openai.createImageVariation({ image: stream });
I get the error:
Uncaught TypeError: source.on is not a function
at Function.DelayedStream.create (/home/ec2-user/environment/node_modules/delayed-stream/lib/delayed_stream.js:33:10)
at FormData.CombinedStream.append (/home/ec2-user/environment/node_modules/combined-stream/lib/combined_stream.js:45:37)
at FormData.append (/home/ec2-user/environment/node_modules/form-data/lib/form_data.js:75:3)
at Object.<anonymous> (/home/ec2-user/environment/node_modules/openai/dist/api.js:454:36)
at Generator.next (<anonymous>)
at /home/ec2-user/environment/node_modules/openai/dist/api.js:21:71
at new Promise (<anonymous>)
at __awaiter (/home/ec2-user/environment/node_modules/openai/dist/api.js:17:12)
at Object.createImageVariation (/home/ec2-user/environment/node_modules/openai/dist/api.js:439:87)
I have also tried:
const response = await openai.createImageVariation({ image: response.Body });
and I get the same error, source.on is not a function
.
TIA