aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
2.96k stars 557 forks source link

[S3][Upload] : Wrong Location in response for file size greater than 5MB #6103

Closed Arun-KumarH closed 1 month ago

Arun-KumarH commented 1 month ago

Checkboxes for prior research

Describe the bug

The location returned from s3 client file upload to cloudserver is correct if the file size is less than 5MB of form <server-name>/<bucketName>/<keyName> (In client config s3ForcePathStyle is set to true). But if the file size is greater than 5MB, then the returned location is of the form <bucketName>.<server-name>/<keyName>.

This seems to happen as s3 client defaults to partSize of 5MB, but the URL / Location returned should be consistent with files greater than 5MB.

SDK version number

aws-sdk version: 2.1621.0

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v20.11.1

Reproduction Steps

const aws = require('aws-sdk');
const fs = require('node:fs');

const s3Client = new aws.S3({
  accessKeyId: "xxxxx",
  secretAccessKey: "xxxxx",
  endpoint: "http://127.0.0.1:8000",
  s3ForcePathStyle: true
});
async function uploadFile(bucket, key) {
  const readableStream = await fs.createReadStream('./5MB.pdf');
  const result = await new Promise((resolve, reject) => {
    s3Client.upload({
      Key: key,
      Bucket: bucket,
      Body: readableStream
    }, (err, data) => {
      if (err) {
        console.log('Error while storing object',
          {
            Key: key, Bucket: bucket, error: err, errStack: err.stack
          });
        resolve(err);
      } else {
        console.log('Object uploaded successfully');
        resolve(data);
      }
    });
  });
  console.log('Upload result', result);
}

uploadFile('tenant', '5MB.pdf').then((err, data) => {
  if (err) {
    console.log('Error', err);
  }
  console.log('Data', data);
});

Observed Behavior

Upload result {
  Location: 'http://tenant.127.0.0.1/5MB.pdf',
  Bucket: 'tenant',
  Key: '5MB.pdf',
  ETag: '"2ec6f604cd08eb2e091b58f666ff0a9f-2"'
}

Expected Behavior

Upload result {
  ETag: '"a3008a5bd4094f4849e533f9bb2c5c89"',
  Location: 'http://127.0.0.1:8000/tenant/5MB.pdf',
  key: '5MB.pdf',
  Key: '5MB.pdf',
  Bucket: 'tenant'
}

Possible Solution

No response

Additional Information/Context

No response

Arun-KumarH commented 1 month ago

Created issue in Wrong repo, will update to v3 and re-open again if this issue persist.

github-actions[bot] commented 1 month 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.