I am developing an app that utilizes the Box Java SDK (Box Api v2). Due to our architecture, I need to upload files via the REST api. Apparently, I am having trouble getting the HTTPUrlConnection configured correctly.
Here is my code:
URL uploadURL = new URL( "https://upload.box.com/api/2.0/files/content" );
uploadConn = (HttpURLConnection)uploadURL.openConnection();
uploadConn.setRequestMethod( "POST" );
uploadConn.setChunkedStreamingMode( 0 ); // enable chunking with default chunk size
uploadConn.setRequestProperty( "Authorization", "Bearer " + boxClient.getAuthData().getAccessToken() );
uploadConn.setRequestProperty( "filename", filename );
if (isNew) uploadConn.setRequestProperty( "parent_id", parentId );
uploadConn.setDoOutput( true );`
For a new file, filename is the name of the file and parentId is the id of the target folder.
Box returns HTTP error 400, so something isn't right with my request.
Thanks in advance for your help!