Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axios does not return XML error message from S3 when uploading asset over the size limit #4548

Open
vlad-bluescape opened this issue Mar 24, 2022 · 2 comments

Comments

@vlad-bluescape
Copy link

vlad-bluescape commented Mar 24, 2022

Describe the issue

Axios does not return XML error message from S3 when uploading asset over the size limit

Example Code

This is the code I am running for the upload to S3:

let dataForm = new FormData();

dataForm.append('key', functionParams.uploadData.fields.key);
dataForm.append('bucket', functionParams.uploadData.fields.bucket);
dataForm.append('X-Amz-Algorithm', functionParams.uploadData.fields['X-Amz-Algorithm']);
dataForm.append('X-Amz-Credential', functionParams.uploadData.fields['X-Amz-Credential']);
dataForm.append('X-Amz-Date', functionParams.uploadData.fields['X-Amz-Date']);
dataForm.append('Policy', functionParams.uploadData.fields.Policy);
dataForm.append('X-Amz-Signature', functionParams.uploadData.fields['X-Amz-Signature']);
dataForm.append('file', fs.createReadStream(functionParams.assetFullPath),
            { knownLength: fs.statSync(functionParams.assetFullPath).size }  
        );

const uploadServiceURL = uploadData.url;

var config = {
            method: 'POST',
            url: uploadServiceURL,
            headers: {
                ...dataForm.getHeaders(),
                'content-length': dataForm.getLengthSync()
            },
            data: dataForm,
            maxContentLength: Infinity,
            maxBodyLength: Infinity,
            transitional: {
                forcedJSONParsing: false,
                silentJSONParsing: false,
                clarifyTimeoutError: true
            }
        };


        axios(config)
            .then(answer => {
                  resolve(answer);
            })
            .catch((error) => {               
                console.log(`Error:`)               
                console.log(error.toJSON())
                reject(error)
            })

Expected behavior, if applicable

Error message from AXIOS should provide the XML error message that S3 returns. Instead, AXIOS fails.

Environment

  • Axios Version : 0.24.0
  • Node.js Version: v14.17.4
  • OS: OS 12.3

Additional context/Screenshots

I am using Axios to upload an asset to S3 using signed URLs.
It works correctly for files under the upload size limit, but when trying to upload an asset (.tiff, 114 Mb) over the upload size limit (50 Mb), I cannot get the XML error from S3.
When I use the request library to run the upload to S3, I get this as the error content :

UPLOAD FAILED. Status Code: 400. Error message: <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>EntityTooLarge</Code><Message>Your proposed upload exceeds the maximum allowed size</Message><ProposedSize>52432788</ProposedSize><MaxSizeAllowed>52428800</MaxSizeAllowed><RequestId>N8RFYCS0K10GB4FF</RequestId><HostId>2OaG69rf19DMxItXx8J//rscZuSbxU8hJ/93du/a1zaFwAZa6jN2v1xCDebW4MRMgW3Kfuw0n10=</HostId></Error>

But when I use AXIOS, I get back the error code 400 (good), but no XML message back:

{
   "message": "Request failed with status code 400",
   "name": "Error",
   "stack": "Error: Request failed with status code 400\n    at createError (/Users/vlad/modules/node_modules/axios/lib/core/createError.js:16:15)\n    at settle (/Users/vlad/modules/axios/lib/core/settle.js:17:12)\n    at IncomingMessage.handleStreamEnd (/Users/vlad/modules/node_modules/axios/lib/adapters/http.js:322:11)\n    at IncomingMessage.emit (events.js:412:35)\n    at endReadableNT (internal/streams/readable.js:1317:12)\n    at processTicksAndRejections (internal/process/task_queues.js:82:21)",
   "config": {
      "transitional": {
         "silentJSONParsing": false,
         "forcedJSONParsing": false,
         "clarifyTimeoutError": true
      },
      "transformRequest": [
         null
      ],
      "transformResponse": [
         null
      ],
      "timeout": 0,
      "xsrfCookieName": "XSRF-TOKEN",
      "xsrfHeaderName": "X-XSRF-TOKEN",
      "maxContentLength": null,
      "maxBodyLength": null,
      "headers": {
         "Accept": "application/json, text/plain, */*",
         "Content-Type": "multipart/form-data; boundary=--------------------------913873697821807580301477",
         "content-length": 114310407,
         "User-Agent": "axios/0.26.0"
      },
      "method": "post",
      "url": "https://s3.us-east-1.amazonaws.com/public-assets.bluescape.com",
      "data": {
         "_overheadLength": 938,
         "_valueLength": 114309413,
         "_valuesToMeasure": [],
         "writable": false,
         "readable": true,
         "dataSize": 0,
         "maxDataSize": 2097152,
         "pauseStreams": true,
         "_released": true,
         "_streams": [],
         "_currentStream": null,
         "_insideLoop": false,
         "_pendingNext": false,
         "_boundary": "--------------------------913873697821807580301477",
         "_events": {},
         "_eventsCount": 1
      },
      "axios-retry": {
         "retryCount": 0,
         "lastRequestTime": 1648080399442
      }
   },
   "status": 400
}

Any idea how can I get back the XML from S3 describing the issue?
I want to present it as the cause of the error. The AXIOS error message ("Request failed with status code 400") does not give any context of what the issue was: file size over the size limit for upload.

Thanks!

@vlad-bluescape
Copy link
Author

Any help?

@mareebsiddiqui
Copy link

I am facing this issue too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants