Skip to main content

 


Because the Java Box SDK does not work for my environment, I'm making REST calls and when I Submit the following request:


 


HttpPost httppost = new HttpPost(baseURl + "/files/content");
HttpEntity reqEntity = MultipartEntityBuilder.create()
.addPart("attributes", new StringBody("{\"name\":\"C7L1HLeXUAEHtgm.jpeg\",\"parent\":{\"id\":\"0\"}}", ContentType.APPLICATION_JSON))
.addPart("file", new FileBody(file, ContentType.create("image/jpg")))
.build();
httppost.setEntity(reqEntity);
httppost.setHeader("Authorization", "Bearer " + accessToken);

 


Because the Java Box SDK does not work for my environment, I'm making REST calls and when I Submit the following request:


HttpPost httppost = new HttpPost(baseURl + "/files/content");
HttpEntity reqEntity = MultipartEntityBuilder.create()
.addPart("attributes", new StringBody("{\"name\":\"C7L1HLeXUAEHtgm.jpeg\",\"parent\":{\"id\":\"0\"}}", ContentType.APPLICATION_JSON))
.addPart("file", new FileBody(file, ContentType.create("image/jpg")))
.build();httppost.setEntity(reqEntity);httppost.setHeader("Authorization", "Bearer " + accessToken);

I get the following response: HTTP/1.1 404 Not Found








Box



































I don't see what I'm missing here. I've been following the instructions from https://developer.box.com/v2.0/reference#upload-a-file.


PS: I already know how to navigate through folders and create new ones.





 I'm not sure I see an error trace here anywhere, just some Java and some HTML/JS. What exact error are you getting?




   the response from Box is a 404 (File Not Found) with the the html body I've attached. I was expecting something else.




I can successfully upload file using postman. I Only need to provide an "Authorization" header and the body as form-data to have two entries.

1. attributes - the JSON String shown above

2. file - the binary of the file




Please ignore this issues as I had made a mistake in passing the URI. The I had the wrong URI




Ah great to hear. Sorry I wasn't able to help much more.




 


 


I am also facing the same issue. I am passing as below


{"name":"abc.txt", "parent":{"id":"0"}}

 id : 0 means file uploading at the root level. what do you mean by this


-F file=@myfile.jpg

and where should I pass this? 



Reply