Skip to main content
Question

file upload failed. (API upload did not contain a file part)

  • May 22, 2025
  • 6 replies
  • 75 views

Forum|alt.badge.img

Hello, I'm paul bae.

file upload frequently failed with java rest template.

not everytime. sometimes success with exactly same request(without filename).

every failed http code is "400" and message is "API upload did not contain a file part".

I don't know how to fix it. 

belows are test upload fail log.

 

 

Request body: --ZCmcwgj21ZGAdw-F5nPyOHYyjoSbz64IvypjSJMc
Content-Disposition: form-data; name="attributes"
Content-Type: application/json;charset=UTF-8

{"name":"upload-test-20220806145130","parent":{"id":"164677862892"}}
--ZCmcwgj21ZGAdw-F5nPyOHYyjoSbz64IvypjSJMc
Content-Disposition: form-data; name="file"; filename="upload-test-20220806145130"
Content-Type: application/octet-stream
Content-Length: 1000

abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl
--ZCmcwgj21ZGAdw-F5nPyOHYyjoSbz64IvypjSJMc--

Response body: {"code":"bad_request","help_url":"http://developers.box.com/docs/#errors","status":400,"message":"API upload did not contain a file part","type":"error"}

6 replies

Forum|alt.badge.img

May I see the code you are running? 

Is there anything else you can share on what the differences are between when it works and when it doesn't? 


Forum|alt.badge.img

I found the reason.

In header, "Content-Type: application/json;charset=UTF-8" is invalid.

invalid content type cuased intermittent server response(400)

remove invalid content type solve the problem.

cc. thx, for asking Alex.


Forum|alt.badge.img

Bae, can you show me an example of the JSON body, i'm having the same problem


Forum|alt.badge.img

It's 3month ago test. so I dont have example.

but it's a plain file request, not complex.

and above i said, my problem is invalid header value.

AS-IS : Content-Type: application/json;charset=UTF-8

TO-BE : Content-Type: application/json;

in my case, that's all.

I hope your issue will be resovled.


Forum|alt.badge.img
---1234567890 
Content-Disposition: form-data; name="attributes" Content-Type: application/json 
{    
"name":"test upload.txt",     
"parent":{        
"id":"182678998283"             
}, }
---1234567890 
Content-Disposition: form-data; name="file"; filename="test upload.txt" 
Content-Type: text/plain  
VGhpcyBpcyBhIHRlc3Q= 
---1234567890" 

Forum|alt.badge.img

Still not working.