public BoxFileUploadSessionPart uploadPart ( byte [ ] data , long offset , int partSize , long totalSizeOfFile ) { URL uploadPartURL = this . sessionInfo . getSessionEndpoints ( ) . getUploadPartEndpoint ( ) ; BoxAPIRequest request = new BoxAPIRequest ( this . getAPI ( ) , uploadPartURL , HttpMethod . PUT ) ; request . addHeader ( HttpHeaders . CONTENT_TYPE , ContentType . APPLICATION_OCTET_STREAM ) ; MessageDigest digestInstance = null ; try { digestInstance = MessageDigest . getInstance ( DIGEST_ALGORITHM_SHA1 ) ; } catch ( NoSuchAlgorithmException ae ) { throw new BoxAPIException ( "Digest algorithm not found" , ae ) ; } //Creates the digest using SHA1 algorithm. Then encodes the bytes using Base64. byte [ ] digestBytes = digestInstance . digest ( data ) ; String digest = Base64 . encode ( digestBytes ) ; request . addHeader ( HttpHeaders . DIGEST , DIGEST_HEADER_PREFIX_SHA + digest ) ; //Content-Range: bytes offset-part/totalSize request . addHeader ( HttpHeaders . CONTENT_RANGE , "bytes " + offset + "-" + ( offset + partSize - 1 ) + "/" + totalSizeOfFile ) ; //Creates the body request . setBody ( new ByteArrayInputStream ( data ) ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject jsonObject = JsonObject . readFrom ( response . getJSON ( ) ) ; BoxFileUploadSessionPart part = new BoxFileUploadSessionPart ( ( JsonObject ) jsonObject . get ( "part" ) ) ; return part ; }
Uploads bytes to an open upload session .