public UploadPartResponse uploadPart ( UploadPartRequest request ) { checkNotNull ( request , "request should not be null." ) ; checkNotNull ( request . getPartSize ( ) , "partSize should not be null" ) ; checkNotNull ( request . getPartNumber ( ) , "partNumber should not be null" ) ; if ( request . getPartSize ( ) > 5 * 1024 * 1024 * 1024L ) { throw new BceClientException ( "PartNumber " + request . getPartNumber ( ) + " : Part Size should not be more than 5GB." ) ; } InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . PUT ) ; internalRequest . addParameter ( "uploadId" , request . getUploadId ( ) ) ; internalRequest . addParameter ( "partNumber" , String . valueOf ( request . getPartNumber ( ) ) ) ; internalRequest . addHeader ( Headers . CONTENT_LENGTH , String . valueOf ( request . getPartSize ( ) ) ) ; InputStream input = request . getInputStream ( ) ; MD5DigestCalculatingInputStream md5DigestStream = null ; if ( request . getMd5Digest ( ) == null ) { try { md5DigestStream = new MD5DigestCalculatingInputStream ( input ) ; input = md5DigestStream ; } catch ( NoSuchAlgorithmException e ) { logger . warn ( "Unable to verify data integrity." , e ) ; } } try { internalRequest . setContent ( this . wrapRestartableInputStream ( input ) ) ; BosResponse response = this . invokeHttpClient ( internalRequest , BosResponse . class ) ; if ( md5DigestStream != null ) { byte [ ] clientSideHash = md5DigestStream . getMd5Digest ( ) ; byte [ ] serverSideHash ; try { serverSideHash = Hex . decodeHex ( response . getMetadata ( ) . getETag ( ) . toCharArray ( ) ) ; } catch ( Exception e ) { throw new BceClientException ( "Unable to verify integrity of data upload." , e ) ; } if ( ! Arrays . equals ( clientSideHash , serverSideHash ) ) { throw new BceClientException ( "Unable to verify integrity of data upload. " + "Client calculated content hash didn't match hash calculated by " + "BOS. " + "You may need to delete the data stored in BOS." ) ; } } UploadPartResponse result = new UploadPartResponse ( ) ; result . setETag ( response . getMetadata ( ) . getETag ( ) ) ; result . setPartNumber ( request . getPartNumber ( ) ) ; return result ; } finally { if ( input != null ) { try { input . close ( ) ; } catch ( Exception e ) { } } } }
Uploads a part in a multipart upload . You must initiate a multipart upload before you can upload any part .