HTTP 500 when trying to upload a file

谁说我不能喝 提交于 2019-12-13 07:43:59

问题


Here is my Box upload POST to upload a file into a specific folder:

POST /api/2.0/files/content HTTP/1.1
Authorization: Bearer ACCESS_TOKEN
Accept: application/json
User-Agent: SOASoftware/7-HttpCore/4
Transfer-Encoding: chunked
Content-Type: multipart/form-data
Host: upload.box.com
Connection: Keep-Alive

attributes='{"name":"lead.txt", "parent":{"id":"2890481033"}}'&file=C:\SOA\Software\sm70\instances\nd\leads.txt
-----------------------------9051914041544843365972754266
<file-data>
-----------------------------9051914041544843365972754266

but I get this response, that doesn't help me to understand what the problem is:

HTTP/1.1 500
Age: 0
Date: Fri, 02 Jan 2015 09:06:09 GMT
Connection: close

EMPTY MESSAGE

Can anyone tell me what I'm doing wrong in my request to cause the HTTP 500, please?


回答1:


It looks like your multipart request isn't properly formatted. The easiest way to do this is to use an SDK or find a library that can build a multipart request for you.

If you really want to build the request manually, then here's an example of what an upload request should look like:

POST https://upload.box.com/api/2.0/files/content HTTP/1.1
Host: upload.box.com
Authorization: Bearer ACCESS_TOKEN
Content-Length: 346
Content-Type: multipart/form-data; boundary=------------------------393329c2f2238ab4

--------------------------393329c2f2238ab4
Content-Disposition: form-data; name="attributes"

{"name":"my-file.txt", "parent":{"id":"0"}}
--------------------------393329c2f2238ab4
Content-Disposition: form-data; name="file"; filename="my-file.txt"
Content-Type: application/octet-stream

<file-data>

--------------------------393329c2f2238ab4--


来源:https://stackoverflow.com/questions/27739758/http-500-when-trying-to-upload-a-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!