Skip to main content
Question

Bad request when uploading a file

  • May 22, 2025
  • 2 replies
  • 30 views

Forum|alt.badge.img

I am using the Box API from within a C++ application using Qt.  Using the Qt library (QNetworkAccessManager, QHttpMultiPart, etc...), I am able to sign in, authenticate, get file listing and file content.  However I have hit a road block with trying to upload a new file.  All I get from the server is "400 Bad request" with no other message.  If anyone can spot my mistake, I would really appreciate it!  I've checked that the parent ID is correct and valid.

 

Here is (an example of) the raw request that I am sending out (the auth token is not shown for security):

 

POST /api/2.0/files/content HTTP/1.1

Authorization: Bearer XXXXXXXXXXXXXXXXXX

Content-Type: multipart/form-data; boundary="boundary_.oOo._MTA5NjYzOTY0Ng==MTUxNzg3MTc2OA==OTEyNTYyMDYz"

MIME-Version: 1.0

Content-Length: 411

Connection: Keep-Alive

Accept-Encoding: gzip, deflate

Accept-Language: en-US,*

User-Agent: Mozilla/5.0

Host: upload.box.com

 

--boundary_.oOo._MTA5NjYzOTY0Ng==MTUxNzg3MTc2OA==OTEyNTYyMDYz

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

 

{"name":"test.json", "parent":{"id":"5***phone number removed for privacy***"}}

--boundary_.oOo._MTA5NjYzOTY0Ng==MTUxNzg3MTc2OA==OTEyNTYyMDYz

Content-Disposition: form-data; name="file.json"

 

{

    "date": "2018/03/01",

    "name": "ABCDEFGHIJKLMNO"

}

 

--boundary_.oOo._MTA5NjYzOTY0Ng==MTUxNzg3MTc2OA==OTEyNTYyMDYz--

 

2 replies

Forum|alt.badge.img

 I tried testing the same type of request using curl, and this is what the headers looked like for a successful request:

 

POST /api/2.0/files/content HTTP/1.1
Host: upload.box.com
User-Agent: curl/7.57.0
Accept: */*
Authorization: Bearer XXXXXXXXXX
Content-Length: 401
Content-Type: multipart/form-data; boundary=------------------------ab85ee32db30d827

One thing I note is the absence of double-quotes around the boundary value in the Content-Type header — could you try removing them and see if that helps?


Forum|alt.badge.img

HI
I am facing the same problem, i was wondering if you found a solution?
Also how did you get the request sent from qt?