private void uploadSampleFile ( ) { mDialog = ProgressDialog . show ( MainActivity . this , getText ( R . string . boxsdk_Please_wait ) , getText ( R . string . boxsdk_Please_wait ) ) ; new Thread ( ) { @ Override public void run ( ) { try { String uploadFileName = "box_logo.png" ; InputStream uploadStream = getResources ( ) . getAssets ( ) . open ( uploadFileName ) ; String destinationFolderId = "0" ; String uploadName = "BoxSDKUpload.png" ; BoxRequestsFile . UploadFile request = mFileApi . getUploadRequest ( uploadStream , uploadName , destinationFolderId ) ; final BoxFile uploadFileInfo = request . send ( ) ; showToast ( "Uploaded " + uploadFileInfo . getName ( ) ) ; loadRootFolder ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } catch ( BoxException e ) { e . printStackTrace ( ) ; BoxError error = e . getAsBoxError ( ) ; if ( error != null && error . getStatus ( ) == HttpURLConnection . HTTP_CONFLICT ) { ArrayList < BoxEntity > conflicts = error . getContextInfo ( ) . getConflicts ( ) ; if ( conflicts != null && conflicts . size ( ) == 1 && conflicts . get ( 0 ) instanceof BoxFile ) { uploadNewVersion ( ( BoxFile ) conflicts . get ( 0 ) ) ; return ; } } showToast ( "Upload failed" ) ; } finally { mDialog . dismiss ( ) ; } } } . start ( ) ; }
Method demonstrates a sample file being uploaded using the file api