0

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?

Greg
  • 3,731
  • 1
  • 29
  • 25
Paul Pogonoski
  • 121
  • 2
  • 10

1 Answers1

0

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--
Greg
  • 3,731
  • 1
  • 29
  • 25
  • Thanks Greg! I'll look for a library, although my solution is based on hand cranking the body, so it wouldn't be too had to amend it to send the correct body. I'm using JavaScript so an SDK is not helpful. – Paul Pogonoski Jan 04 '15 at 22:40
  • Greg, I've done some more testing and adding the boundary parameter on the Content-Type header results in an http 400 (bad request) from the BOX API. removing that parameter give me a 500 when formatted as above. I really need the Box API guys to step in here! – Paul Pogonoski Jan 05 '15 at 06:54
  • I just double checked, and the example above should successfully upload a file. Make sure that your request is properly formatted with the correct Content-Length, Content-Disposition, and Content-Type headers. The [API documentation](https://developers.box.com/docs/#files-upload-a-file) also has a cURL snippet that can be used to test uploads. – Greg Jan 05 '15 at 22:43
  • Ah! I missed the Content-Lenth header.... how do you determine the content length with the byte data? – Paul Pogonoski Jan 05 '15 at 23:01
  • Nope...creating a proper content-length still doesn't do it. What I need id the Box API guys to have a look at the server log and tell me what's causing the 500 from them. – Paul Pogonoski Jan 06 '15 at 00:10