KeyTOOLongError when we are creating pre-signed error with x-amz-security-token programatically

43 views Asked by At

For creating Pre-signed URL programmatically using Apex, the following steps mentioned below are performed.

1)we have created a pre-signed URL on the object that is uploaded in s3 bucket from AWS Console . A

We have created a pre-signed URL in the console using the option mentioned in the above screenshot. The pattern of URL that is created is in the below format.

https://bucketname.s3.region.amazonaws.com/filename?response-content-disposition=inline&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEK7%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCmFwLXNvdXRoLTEiRzBFAiEApJ2FtFhuEdqn0N8XGEpdio6m8t%2FdexfnCkhPvGzjBbsCIC1l6D%2B2gTN7uPE8bPmINi17Go0aOHp3P4uYrSeTYn9BKuwDCCcQAxoMMTI3MDIzNTYxODAwIgy4Q0OFJANoSVhOFBkqyQN8hdjf%2BQYdux5bvAnyaY%2Bqb6PKGXjEI8GuW%2BcD3nQSYpPd3QWakM0xXvJUblBJBsDjFNY%2FBjDuG%2FsQ5iajLtJRAflU35Xiob%2BxRb%2Fhq0kmFZddDQyGpJppPlUeunuodNhn9FDJjyal0pYnGVm7AkWZjMQJLfb2xKmepbpjS13VweAtgKj9Wo8IBQZuzMvBD7vYjO4C1wKI2qVbIQrTTZ6TmSTdoxNI4htT%2B8nU9ziie1EK6l1JUZKoVcfU8gTL8TDs3p5aZ4sXRfRe6av5qwFIy%2BP8oi4dK%2FsZnD%2BkE9qXKXnzccS8d6tjFviU9kH8t%2Bsm%2FhJwoVHoTPMB%2B3t%2BgcaL8B1g7leiDeGO5ZgqihWrP9WTpqDzh0Ve04eG6DbNC0ZN0AfkdgsvxnTVIwMt9Fd%2F5I4Peoi%2BvIL48%2BGAWIxtHnvGVjRJmjXibMR4F7P8KHBzAV4%2Bj3DaM2mt4i2%2FYXHt1lKvTmxgA5j%2FHFNXxmdc0NPFdb4lvx0kzgQAm2Dt9eE4DYMoZo8lvKHc01UDmM9cx3g6oHBiw%2FZEFmrfbYoTMDrTN7YmXMrh26bp7lyjfowAlkH%2FtOV1EVjIsDmvCE5Zuw9q4NMPCOjkMM7q36sGOpQCldh5Lg54yR5QDwqQKu4GQ1j3xpQKZyMGsWXYtpimFJo4sJ9jBHY%2BL4pihGBZ54pV4gV4%2BMyVN%2BRjl9dv2zqsnaCb25uw4LPW%2FLMveWcfRY5USSY7k2s16kxZouQxD%2FvY4urGQOEhfT2M0UUsSCDV0VayU%2FfIwgHT6VO0FTrGt0LmfbyFJ4h21yWUGIKeE633No53hh1qIj%2BLZTELNdjww9soip9x1gOa6M0Fxd7XfTw5egdgl6hrGi9xjZ7jOXmN7tMx44HXCxtZcsrlFz65zIAdyxBq1545ausC8iCBk%2Fjdtp7CL7oDnOre6MlLQLOmTrsBdO0KbzudiHanWle%2BSyIZ7%2FKKLGMAckjFK5VRMPhgslhJ&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20231212T165327Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Credential=ASIAR3EZRXREJ7TWK4VB%2F20231212%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=776633f912ce1960a27901443e45c01b173ee10769e29705627f4ed822b7f054

We followed the same pattern for creating Pre-signed URL Programmatically in Apex.

USER_DEBUG|[6]|DEBUG|---------------https://bucketname.s3.us-east-1.amazonaws.com/locationoffile?response-content-disposition=inline&X-Amz-Security-Token=IQoJb3JpZ2luX2VjELP%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCXVzLWVhc3QtMSJHMEUCIQCJOPGHdvqWJ18xtc%2BTSPrDDL2GFdDMRhg1yz7yc9ceWQIgIsGU1Ck2Er2tAOK4kNyWt%2F6i%2FMmfDnJGpCjQZVvFYCgqkwMILBADGgwxMjcwMjM1NjE4MDAiDLeYQLg8%2BL2sYbJLdyrwAovr4WAHHvT7DxtXsSHEXr2dgPKF09RWubBnnrZbVCgrEY5ry%2Fs5psemq25f%2FS%2Bozos4VheIv8AXbVGSSpzSMV8mhN9mGXyxY0ckb4ExPV4gPB4IHpFigZ%2FLtfo2TUSeMRSoQFuyoECkm%2BmZJLOaJYjr4DoArtfkZ28QX0S6MjN2PkZv8OHddcgSwg%2BNoDCKGrGz9e2%2BhKmMOlbXbLS90ojlxHXPlUJgt%2Bx6V9WUV2sZchSTRvdvP7bCMfMfm7nubYZCK8jJhb4KEEBMZ4SVdjVyNW547NXguWJx2rd9gVyNemwoiXQW7juJ0tYpxG63jtL7AcjOyIvytv32MysKpJPWfOeaFQBMGZAMjkrzUZKP0a%2Fmb6qxpwEyScJ33zd3OdQaWaoqCF9foRjhUo6exxI%2FVkEZ7NphFHM8ksF2cR0vjY%2Bq8ujVFsa2HUiwUGZAeO2iRH0MOnX9XiodM69whh0HxLcmjAc7HdngMUth250BMI3t4KsGOqYByyzzVgwWPxPoZWy%2BAq1mtOiiESy9c29a3HF7btXW4DfYAF28Pu0Ph4xCHj3HnyGX4pAcyhRj9n2yyQLFN7WXns49rMrlmqS1T2CrdULDHW6IW0jyxlz47yJc5e01X6kC%2FffFya6hftDZCPe9lgboC81Lb1FnA0UdQSPqaJWj3uA%2FNei6JrxcEN6IjkhtiEL%2FdRq%2F2hzv07D%2BxAUYfrZ9VSmTkaoZbw%3D%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20231212T134111Z&X-Amz-SignedHeaders=host&X-Amz-Expires=5000&X-Amz-Credential=ASIAR3EZRXREHIBITJGR%2F20231212%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=4b99afc9fa225ab210ba314c591bc724f77b3f7994cca815f110dff597223db0

we are getting KeyTooLong Error when we try to use the Pre-signed URL as the length of URL is more than 1024 Characters.

The Pre-signed URL that we created in the console is also more than 1024 characters and we can download the document if we pass that URL in the browser. But the same URL when we created programmatically, we are getting the above-mentioned Error.

Any suggestions for resolving the issue?

Expecting solution for the above mentioned issue

0

There are 0 answers