Error doesn't include explanatory code when requesting upload session
I'm using the axios Node library within an AWS lambda to send API requests. This works fine for many of the APIs, but for https://developer.box.com/en/reference/post-files-upload-sessions/ it throws this error object:
{
"message": "Request failed with status code 400",
"name": "Error",
"stack": "Error: Request failed with status code 400\n at createError (/var/task/node_modules/axios/lib/core/createError.js:16:15)\n at settle (/var/task/node_modules/axios/lib/core/settle.js:17:12)\n at IncomingMessage.handleStreamEnd (/var/task/node_modules/axios/lib/adapters/http.js:237:11)\n at IncomingMessage.emit (events.js:203:15)\n at IncomingMessage.EventEmitter.emit (domain.js:448:20)\n at endReadableNT (_stream_readable.js:1143:12)\n at process._tickCallback (internal/process/next_tick.js:63:19)",
"config": {
"url": "https://upload.box.com/api/2.0/files/upload_sessions",
"method": "post",
"data": "{\"folder_id\":\"notTheRealId\",\"file_size\":16787785,\"file_name\":\"notTheRealFilename.mp4\"}",
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json",
"Authorization": "Bearer notTheRealAccessToken",
"User-Agent": "axios/0.19.0",
"Content-Length": 129
},
"transformRequest": [
null
],
"transformResponse": [
null
],
"timeout": 0,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1
}
}
This object doesn't conform to the description at https://developer.box.com/en/reference/resources/client-error/ In particular, there is no "code" property showing one of the explanatory values listed at https://developer.box.com/en/reference/post-files-upload-sessions/#response--400--application/json
I suspect that the API doesn't like that file_size is under 50M. I'm hesitant to structure my client around a magic number like that (by calling https://developer.box.com/en/reference/post-files-content/ for smaller files but this api for larger ones) and would prefer that the choice be driven by error codes.
-
Hi ,
Thanks for highlighting that the endpoint isn't sending back errors that conform to the standards being used within the other endpoints. We'll take that internally and look into it.
The issue could be that the file size is probably under 20mb (as outlined in the restrictions here). In the errors that should be returned under this scenario, that type of error should come back as a 400 error with the description of file_size_too_small: file_size is below minimum file size for uploads via this API. If that's the cause then there might not be something working correctly. We'll have to dig into that.
- Jon
-
After digging further, it seems the failed request is actually never sent, but instead is a failure in the NodeJs Axios library because it seems not to support POST or PUT with a body that's a byte array. See https://github.com/axios/axios/issues/1250#issuecomment-582657318
I'm now looking into Box's Node SDK, but the sample for uploading a part includes a part_id without any explanation of how to get a part ID.
-
Hi ,
Good catch on the axios issue. For the chunked uploader use in the Node SDK, check out this guide. It'll walk you through the entire process with the Node code samples and explain what everything is.
- Jon
-
Hi
A few questions:
1) https://developer.box.com/en/reference/post-files-content/ says "For file sizes over 50MB we recommend using the Chunk Upload APIs." while you pointed me to https://developer.box.com/en/guides/uploads/chunked/ which says "The Chunked Upload API is intended for large files with a minimum size of 20MB." Should my magic number be 20 or 50 MB?
2) I asked about there being no explanation of how one gets a "part_id" to upload a part. You pointed me to https://developer.box.com/en/guides/uploads/chunked/ which links to https://developer.box.com/en/guides/uploads/chunked/upload-part/ and the Node tab there for a sample request includes "part_id" but nowhere else does it explain how to get one so it can be included in the request.
3) I'm considering switching from your REST API to your Node SDK, so I looked at https://developer.box.com/en/guides/uploads/chunked/with-sdks/ The example involves a stream read from a file, but what I need to upload is a byte array representing the file contents. Can you point me to any sample uses of the Node SDK for uploading a byte array (aka buffer)?
Thanks for your rapid and detailed responses!
サインインしてコメントを残してください。
コメント
4件のコメント