aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.12k stars 579 forks source link

Some of the images uploaded to s3 appear gray. #5569

Closed steel-hyuk closed 11 months ago

steel-hyuk commented 11 months ago

Checkboxes for prior research

Describe the bug

I am trying to upload an image using @aws-sdk/client-s3 and @aws-sdk/lib-storage.

It is uploaded to s3, but when you look at the uploaded image, the bottom part appears gray as in the image below.

스크린샷 2023-12-12 오후 5 40 13

What can i try to solve this problem?

SDK version number

"@aws-sdk/client-s3": "^3.470.0", "@aws-sdk/lib-storage": "^3.470.0",

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

16.20.2

Reproduction Steps

import { Resolver, Mutation, Args } from '@nestjs/graphql';
import { FileUpload, GraphQLUpload } from 'graphql-upload';

  @Mutation(() => ImageUploadResult)
  async uploadImage(
    @Args('input') input: ImageUploadInput,
    @Args('file', { name: 'file', type: () => GraphQLUpload }) file: FileUpload
  ): Promise<ImageUploadResult> {
    // const uploadDir = './uploads';
    // if (!fs.existsSync(uploadDir)) {
    //   fs.mkdirSync(uploadDir);
    // }
    // const randomN = Math.floor(Math.random() * 1000);
    // const filePath = path.join(uploadDir, `${randomN}${file.filename}`);
    // const fileStream = fs.createWriteStream(filePath);
    // file.createReadStream().pipe(fileStream);

   const upload = new Upload({
      client: new S3Client({
        region: mys3region,
        credentials: {
          accessKeyId: mys3accessKeyId,
          secretAccessKey: mys3secretAccessKey
        }
    });,
      params: {
        Bucket: mys3bucketName,
        Key: file.filename,
        Body: file.createReadStream()
      }
    });

    try {
      const result = await upload.done();
      return { imageUrl: result['Location'] };
    } catch (error) {
      throw new Error(ErrorMessage.FailedToUploadImage);
    }
  }

Observed Behavior

No error occurs.

Expected Behavior

I hope i see a normal image

Possible Solution

No response

Additional Information/Context

If i save the file in the local environment and check, it is normal.

github-actions[bot] commented 10 months ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.