amazon s3 – Upload file via @aws-sdk/client-s3 and graphql-upload

S3(‘@aws-sdk/client-s3’) upload function

import { Upload } from ‘@aws-sdk/lib-storage’;

async s3UploadPhoto(fileStream, name, mimetype) {
 const fileKey = this.getFileKey(name);

 const sendParams: PutObjectCommandInput = {
   Bucket: process.env.AWS_BUCKET_NAME,
   Body: fileStream,
   Key: fileKey,
   ContentType: mimetype,
 try {
  const parallelUploads3 = new Upload({
    client: this.s3,
    tags: [],
    queueSize: 4, 
    leavePartsOnError: false,
    params: sendParams,

  parallelUploads3.on('httpUploadProgress', (progress) => {

  return parallelUploads3.done();

 } catch (e) {
  throw new BadRequestException('');

And Graphql upload code via ‘graphql-upload’

 const fileStream = file.createReadStream();

  await this.s3Service.s3UploadPhoto(

I get error: ReferenceError: ReadableStream is not defined

If uploads a file to s3 without lib-storage, I get error: Are you using a Stream of unknown length as the Body of a PutObject request? Consider using Upload instead from @aws-sdk/lib-storage.

What is wrong written that I get error “ReadableStream is not defined”?

Read more here: Source link