aws-sdk-js-v3 icon indicating copy to clipboard operation
aws-sdk-js-v3 copied to clipboard

[s3.copyObject]: Invalid character in header content ["x-amz-copy-source"]

Open shadoworion opened this issue 1 year ago • 11 comments

Checkboxes for prior research

Describe the bug

It looks like the "copyObject" function does not support Hebrew in the location path.

Regression Issue

  • [ ] Select this option if this issue appears to be a regression.

SDK version number

@aws-sdk/[email protected]

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

22.8.0

Reproduction Steps

const oldLocation = "Files/ce59edb1-c78a-4e47-9cc1-b631b3f6e03b/דוד-טסט_orders_2024-10-28 (2).csv";
const newLocation = "Files/236bf060-db65-45fb-be2a-8d5845a75f6d/דוד-טסט_orders_2024-10-28 (2).csv";

await s3.copyObject({
      CopySource: `${process.env.AWS_STORAGE_BUCKET}/${oldLocation}`,
      Bucket: process.env.AWS_STORAGE_BUCKET,
      Key: newLocation,
});

Observed Behavior

TypeError: Invalid character in header content ["x-amz-copy-source"]
    at ClientRequest.setHeader (node:_http_outgoing:702:3)
    at new ClientRequest (node:_http_client:295:14)
    at request (node:https:379:10)
    at /backend/node_modules/@smithy/node-http-handler/dist-cjs/index.js:349:19
    at new Promise (<anonymous>)
    at _NodeHttpHandler.handle (/backend/node_modules/@smithy/node-http-handler/dist-cjs/index.js:283:12)
    at /backend/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:534:18
    at /backend/node_modules/@smithy/middleware-serde/dist-cjs/index.js:33:24
    at /backend/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:485:18
    at /backend/node_modules/@smithy/middleware-retry/dist-cjs/index.js:320:38 {
  code: 'ERR_INVALID_CHAR',
  '$metadata': { attempts: 1, totalRetryDelay: 0 }
}

Expected Behavior

Not to get an error

Possible Solution

No response

Additional Information/Context

No response

shadoworion avatar Oct 29 '24 09:10 shadoworion

Hey @shadoworion ,

I can reproduce this issue

import { S3Client, GetObjectCommand, CopyObjectCommand } from "@aws-sdk/client-s3";

// Initialize the S3 client
const s3Client = new S3Client({
  region: "us-east-1", // Replace with your region
});
const copyObjectCommand = new CopyObjectCommand({
  CopySource: `new-bucket-maggie-ma/דוד-טסט_`,
  Bucket: "new-bucket-maggie-ma",
  Key: "דוד-טסט_new",
});
const resCopyObject = await s3Client.send(copyObjectCommand);
console.log(resCopyObject);

The error I got

node:_http_outgoing:662
  validateHeaderValue(name, value);
  ^

TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["x-amz-copy-source"]
    at ClientRequest.setHeader (node:_http_outgoing:662:3)
    at new ClientRequest (node:_http_client:289:14)
    at request (node:https:379:10)
    at /Users/zshzbh/Desktop/newProj/node_modules/@smithy/node-http-handler/dist-cjs/index.js:349:19
    at new Promise (<anonymous>)
    at _NodeHttpHandler.handle (/Users/zshzbh/Desktop/newProj/node_modules/@smithy/node-http-handler/dist-cjs/index.js:283:12)
    at /Users/zshzbh/Desktop/newProj/node_modules/@smithy/smithy-client/dist-cjs/index.js:197:35
    at /Users/zshzbh/Desktop/newProj/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:534:24
    at /Users/zshzbh/Desktop/newProj/node_modules/@smithy/middleware-serde/dist-cjs/index.js:33:30
    at /Users/zshzbh/Desktop/newProj/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:485:24 {
  code: 'ERR_INVALID_CHAR',
  '$metadata': { attempts: 1, totalRetryDelay: 0 }
}

I will reach out to service team and check if there's an updates. Thanks!

zshzbh avatar Nov 01 '24 17:11 zshzbh

Hey @zshzbh

Any updates?

shadoworion avatar Dec 02 '24 17:12 shadoworion

Hey @shadoworion .

I haven't got back from service team, I will follow up this issue with them. Internal ref- V1599096015

Thanks! Maggie

zshzbh avatar Dec 02 '24 17:12 zshzbh

@shadoworion @zshzbh, try to wrap CopySource and Key value with encodeURI function

Nitro-N avatar Dec 12 '24 07:12 Nitro-N

@Nitro-N Thanks for the workaround solution. I think we can use the encode function as a workaround now, but still I want to let the service team know this issue. I have not received anything from service team yet, will try to reach out again.

Sorry for the wait and thanks for the provided workaround

zshzbh avatar Jan 03 '25 21:01 zshzbh

@shadoworion @zshzbh, try to wrap CopySource and Key value with encodeURI function I have the same problem, but encodeURI can't work;

ChrisSong1994 avatar Mar 11 '25 13:03 ChrisSong1994

@Nitro-N Thanks for the workaround solution. I think we can use the encode function as a workaround now, but still I want to let the service team know this issue. I have not received anything from service team yet, will try to reach out again.

Sorry for the wait and thanks for the provided workaround

What is the progress on this issue now?

ChrisSong1994 avatar Mar 11 '25 13:03 ChrisSong1994

Hey @ChrisSong1994 ,

Thanks for the followup. I really understand how stressful this could be, however, the service team has some other high priority requests and they won't fix this issue in a couple weeks.

The workaround is available though, could you please use the workaround for now? If you want to get a faster fix, I'd like to suggest you to list the impact of this issue, or reach out to your TAM to submit an internal ticket. Usually these two steps could make this issue getting triaged by service team faster.

Thanks for being patient!

zshzbh avatar Mar 12 '25 21:03 zshzbh

@zshzbh

Hi, any updates?

shadoworion avatar Apr 29 '25 08:04 shadoworion

Hey @shadoworion ,

Got response from service team and they want to confirm that if you try URL-encode the special characters?

zshzbh avatar May 01 '25 19:05 zshzbh

Hey @shadoworion ,

Got response from service team and they want to confirm that if you try URL-encode the special characters?

Yes, it works. The problem is only in "CopySource". "Key" parameter works without URL-encode.

shadoworion avatar May 01 '25 19:05 shadoworion