public Slot requestSlot ( String filename , long fileSize , String contentType , DomainBareJid uploadServiceAddress ) throws SmackException , InterruptedException , XMPPException . XMPPErrorException { final XMPPConnection connection = connection ( ) ; final UploadService defaultUploadService = this . defaultUploadService ; // The upload service we are going to use. UploadService uploadService ; if ( uploadServiceAddress == null ) { uploadService = defaultUploadService ; } else { if ( defaultUploadService != null && defaultUploadService . getAddress ( ) . equals ( uploadServiceAddress ) ) { // Avoid performing a service discovery if we already know about the given service. uploadService = defaultUploadService ; } else { DiscoverInfo discoverInfo = ServiceDiscoveryManager . getInstanceFor ( connection ) . discoverInfo ( uploadServiceAddress ) ; if ( ! containsHttpFileUploadNamespace ( discoverInfo ) ) { throw new IllegalArgumentException ( "There is no HTTP upload service running at the given address '" + uploadServiceAddress + ' ' ) ; } uploadService = uploadServiceFrom ( discoverInfo ) ; } } if ( uploadService == null ) { throw new SmackException . SmackMessageException ( "No upload service specified and also none discovered." ) ; } if ( ! uploadService . acceptsFileOfSize ( fileSize ) ) { throw new IllegalArgumentException ( "Requested file size " + fileSize + " is greater than max allowed size " + uploadService . getMaxFileSize ( ) ) ; } SlotRequest slotRequest ; switch ( uploadService . getVersion ( ) ) { case v0_3 : slotRequest = new SlotRequest ( uploadService . getAddress ( ) , filename , fileSize , contentType ) ; break ; case v0_2 : slotRequest = new SlotRequest_V0_2 ( uploadService . getAddress ( ) , filename , fileSize , contentType ) ; break ; default : throw new AssertionError ( ) ; } return connection . createStanzaCollectorAndSend ( slotRequest ) . nextResultOrThrow ( ) ; }
Request a new upload slot with optional content type from custom upload service .