Closed wahab-khurram-dev closed 1 year ago
Hi @wahabfun, thanks for opening this issue. Could you please let me know if this issue is persistent or happens randomly?, I just tried on my machine and I got not issues, however, there are some scenarios where this problem could happen, and one of them is if the date being parsed for some reason is undefined. After looking at the code I found two places, inside of the presigned post implementation, from where this issue could occur:
One is here:
const signingDate = iso8601(now).replace(/[-:]/g, "");
We will get an error from the line above if the parameter given "now" is undefined, but how could that variable be undefined, well the only way I see for this to happen is if "systemClockOffset" is also undefined. I see that systemClockOffset is resolved from the client config so that we would need to investigate any case where this configuration "systemClockOffset" will be resolved as undefined. Lets see after here:
const { systemClockOffset, base64Encoder, utf8Decoder, sha256 } = client.config; const now = new Date(Date.now() + systemClockOffset);
And the other place is here, however, if "now" is undefined, it should never reach this point.
So, I will be awaiting for your response to see if this issue is sporadically or persistent, and in case is persistent we could then check other aspect from your environment that could help us reproducing this issue.
Steps I took to reproduce:
npm init
npm i @aws-sdk/client-s3
npm i @aws-sdk/s3-presigned-post
import { S3Client } from "@aws-sdk/client-s3";
import { createPresignedPost } from "@aws-sdk/s3-presigned-post";
let options = { region: process.env.TEST_REGION } let s3Client = new S3Client(options); (async function() { const params = { Bucket: process.env.TEST_BUCKET, Key: process.env.TEST_KEY, Fields: { key: process.env.TEST_KEY, 'content-type': 'video/mp4', 'content-length': '3682374' }, Expires: 600 };
try {
const response = await createPresignedPost(s3Client, params);
console.log(response)
} catch(err) {
console.log(err);
}
})();
- Run the code: ``` node src/index.js```
Thanks!
@yenfryherrerafeliz Thank you for the reply. Yes the error is persistent.
@yenfryherrerafeliz Also would you be so kind if you can tell me the temporary fixing of the bug so I will update the code and will continue the development of my project.
Thank You!
@yenfryherrerafeliz
I have consoled log your investigated variable and from the log it seems that the client.config object only have the "update" property.
Date.now is working fine.
Here is the log output
Aws client.config output { update: [Function: update] }
Date.now output 1674498549009
@wahabfun that is really weird, you should really get a lot of things more, when logging the client's config. For example, check my output:
Would you be able to create an empty project, just to test, by using the repro steps that I put here, and let me know if you also have issues there.
Thanks!
@yenfryherrerafeliz Thank you so much for the help!
Sorry were busy. I just tried it with the empty and it is working fine. So for my original project I reinstalled the s3 nodejs modules and everything is working smooth!
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.
Checkboxes for prior research
Describe the bug
I am getting the following error
RangeError: Invalid time value at Date.toISOString ()
at iso8601 (D:\proj\node_modules\@aws-sdk\s3-presigned-post\dist-cjs\createPresignedPost.js:65:32)
65th code line on @aws-sdk\s3-presigned-post\dist-cjs\createPresignedPost.js is const iso8601 = (date) => date.toISOString().replace(/.\d{3}Z$/, "Z");
SDK version number
@aws-sdk/s3-presigned-post@3.254.0
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
v14.19.3
Reproduction Steps
Observed Behavior
RangeError: Invalid time value at Date.toISOString ()
at iso8601 (D:\proj\node_modules\@aws-sdk\s3-presigned-post\dist-cjs\createPresignedPost.js:65:32)
Expected Behavior
There should be no RangeError: Invalid time value error
Possible Solution
No response
Additional Information/Context
No response