我在通过npm multer使用Box API上传多个文件时遇到问题。
我可以添加代码,但是代码量太大,这是我正在寻找的诊断Box API上传方式的方法。
我可以使用node.js中的Box API直接上传文件,
const fileReadStream = fileSystem.createReadStream(filePath);
预请求的全文如下:
{
"urlProvider": "https://upload.box.com/api/2.0/files/content",
"multipart": {
"attributes": "{\"name\":\"banana-2019-02-15T20:43:30.651Z.png\",\"parent\":{\"id\":\"67056331004\"}}",
"file": {
"value": {
"_readableState": {
"objectMode": false,
"highWaterMark": 65536,
"buffer": {
"head": null,
"tail": null,
"length": 0
},
"length": 0,
"pipes": null,
"pipesCount": 0,
"flowing": null,
"ended": false,
"endEmitted": false,
"reading": false,
"sync": true,
"needReadable": false,
"emittedReadable": false,
"readableListening": false,
"resumeScheduled": false,
"emitClose": false,
"destroyed": false,
"defaultEncoding": "utf8",
"awaitDrain": 0,
"readingMore": false,
"decoder": null,
"encoding": null
},
"readable": true,
"_events": {},
"_eventsCount": 1,
"path": "/Users/jeffrey.tanner/github/jeff00docusign/act-archive-box/tests-dev/files/banana.png",
"fd": null,
"flags": "r",
"mode": 438,
"end": null,
"autoClose": true,
"bytesRead": 0,
"closed": false
},
"options": {
"filename": "banana-2019-02-15T20:43:30.651Z.png",
"contentType": null
}
}
},
"headers": {
"authorization": "Bearer [ACCESS_TOKEN]",
"Content-Type": "multipart/form-data"
}
}
这将返回HTTP状态成功创建201 。
当我通过_handleFile()
中的multer发出相同的请求时:
{
"urlProvider": "https://upload.box.com/api/2.0/files/content",
"multipart": {
"attributes": "{\"name\":\"banana-2019-02-15T20:41:05.723Z.png\",\"parent\":{\"id\":\"67057354030\"}}",
"file": {
"value": {
"_readableState": {
"objectMode": false,
"highWaterMark": 16384,
"buffer": {
"head": null,
"tail": null,
"length": 0
},
"length": 0,
"pipes": null,
"pipesCount": 0,
"flowing": null,
"ended": false,
"endEmitted": false,
"reading": false,
"sync": true,
"needReadable": false,
"emittedReadable": false,
"readableListening": false,
"resumeScheduled": false,
"emitClose": true,
"destroyed": false,
"defaultEncoding": "utf8",
"awaitDrain": 0,
"readingMore": false,
"decoder": null,
"encoding": null
},
"readable": true,
"_events": {},
"_eventsCount": 3,
"truncated": false
},
"options": {
"filename": "banana-2019-02-15T20:41:05.723Z.png",
"contentType": null
}
}
},
"headers": {
"authorization": "Bearer [ACCESS_TOKEN]",
"Content-Type": "multipart/form-data"
}
}
我收到 HTTP状态错误400 :
{
"statusCode": 400,
"res": {
"statusCode": 400,
"body": "",
"headers": {
"date": "Fri, 15 Feb 2019 20:41:15 GMT",
"content-type": "text/html; charset=UTF-8",
"content-length": "0",
"connection": "close",
"age": "0",
"strict-transport-security": "max-age=31536000"
},
"request": {
"uri": {
"protocol": "https:",
"slashes": true,
"auth": null,
"host": "upload.box.com",
"port": 443,
"hostname": "upload.box.com",
"hash": null,
"search": null,
"query": null,
"pathname": "/api/2.0/files/content",
"path": "/api/2.0/files/content",
"href": "https://upload.box.com/api/2.0/files/content"
},
"method": "POST",
"headers": {
"authorization": "Bearer [ACCESS_TOKEN]",
"Content-Type": "multipart/form-data; boundary=--------------------------634091237889493893491401",
"content-length": 417
}
}
}
}
我可以执行哪些步骤来诊断此问题?
到目前为止,我没有发现任何错误消息可以帮助我为什么出现400错误。
谢谢您,谢谢您。