@ Override public InputStream getAttachment ( final Asset asset , final Attachment attachment ) throws IOException , BadVersionException , RequestFailureException { // accept license for type CONTENT HttpURLConnection connection ; if ( attachment . getType ( ) == AttachmentType . CONTENT ) { connection = createHttpURLConnection ( attachment . getUrl ( ) + "?license=agree" ) ; } else { connection = createHttpURLConnection ( attachment . getUrl ( ) ) ; } // If the attachment was a link and we have a basic auth userid + password specified // we are attempting to access the files staged from a protected site so authorise for it if ( attachment . getLinkType ( ) == AttachmentLinkType . DIRECT ) { if ( ( loginInfo . getAttachmentBasicAuthUserId ( ) != null ) && ( loginInfo . getAttachmentBasicAuthPassword ( ) != null ) ) { String userpass = loginInfo . getAttachmentBasicAuthUserId ( ) + ":" + loginInfo . getAttachmentBasicAuthPassword ( ) ; String basicAuth = "Basic " + encode ( userpass . getBytes ( Charset . forName ( "UTF-8" ) ) ) ; connection . setRequestProperty ( "Authorization" , basicAuth ) ; } } connection . setRequestMethod ( "GET" ) ; testResponseCode ( connection ) ; return connection . getInputStream ( ) ; }
Returns the contents of an attachment