[s3.copyObject]: Invalid character in header content ["x-amz-copy-source"]
Checkboxes for prior research
- [X] I've gone through Developer Guide and API reference
- [X] I've checked AWS Forums and StackOverflow.
- [X] I've searched for previous similar issues and didn't find any solution.
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
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!
Hey @zshzbh
Any updates?
Hey @shadoworion .
I haven't got back from service team, I will follow up this issue with them. Internal ref- V1599096015
Thanks! Maggie
@shadoworion @zshzbh, try to wrap CopySource and Key value with encodeURI function
@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
@shadoworion @zshzbh, try to wrap
CopySourceandKeyvalue withencodeURIfunction I have the same problem, butencodeURIcan't work;
@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?
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
Hi, any updates?
Hey @shadoworion ,
Got response from service team and they want to confirm that if you try URL-encode the special characters?
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.