Skip to content

Wrong Location returned using new Javascript SDK #8315

@luantoningalvan

Description

@luantoningalvan

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When I upload something using the new S3 javascript library, the Location attr returned is wrong(without de port). Obs: My bucket name is revendi.

import {
  CompleteMultipartUploadCommandOutput,
  S3Client,
} from "@aws-sdk/client-s3";
import { Upload } from "@aws-sdk/lib-storage";

export class WasabiService {
  private client: S3Client;

  constructor() {
    const endpoint =
      process.env.NODE_ENV === "production"
        ? "https://s3.wasabisys.com"
        : "http://localhost:4566";

    this.client = new S3Client({
      region: process.env.AWS_REGION,
      forcePathStyle: true,
      endpoint: endpoint,
    });
  }

  public saveFile(
    key: string,
    body: Buffer
  ): Promise<CompleteMultipartUploadCommandOutput> {
    const parallelUploads3 = new Upload({
      client: this.client,
      params: {
        Bucket: process.env.BUCKET_NAME,
        Key: key,
        Body: body,
        ACL: "public-read",
      },
    });

    return parallelUploads3.done();
  }
}

Returned Location: http://localhost/revendi/0z0wbqra97k.jpg

Expected Behavior

But everthing works fine when I use the old SDK

import aws, { S3 } from "aws-sdk";

export class WasabiService {
  private client: S3;

  constructor() {
    this.client = new aws.S3({
      endpoint:
        process.env.NODE_ENV === "production"
          ? "https://s3.wasabisys.com"
          : "http://localhost:4566",
      s3ForcePathStyle: true,
    });
  }

  public async saveFile(
    key: string,
    body: Buffer
  ): Promise<S3.ManagedUpload.SendData> {
    const result: S3.ManagedUpload.SendData = await new Promise((res, rej) => {
      this.client.upload(
        {
          Bucket: process.env.BUCKET_NAME,
          Key: key,
          ACL: "public-read",
          Body: body,
        },
        (err, data) => {
          if (err) {
            rej(err);
          }
          res(data);
        }
      );
    });

    return result;
  }
}

Returned Location: http://localhost:4566/revendi/qkusljoq7z.jpg

How are you starting LocalStack?

With a docker-compose file

Steps To Reproduce

Create a projet with the new S3 sdk

Environment

- OS:Ubuntu 22.04
- LocalStack:latest

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions