agave-apps/clients/AbstractService.java
/**
	 * Post a multipart form with file to the api.
	 * 
	 * @param endpoint URL to which to post the form.
	 * @param token AuthenticationToken used for the request
	 * @param nvps List of form variables.
	 * @param file File object to upload
	 * @return
	 * @throws APIClientException
	 */
Post a multipart form with file to the api.

@param endpoint URL to which to post the form.
@param token AuthenticationToken used for the request
@param nvps List of form variables.
@param file File object to upload
@return
@throws APIClientException
Post a multipart form with file to the api . @param endpoint URL to which to post the form . @param token AuthenticationToken used for the request @param nvps List of form variables . @param file File object to upload @return @throws APIClientException
public APIResponse post(String endpoint, AuthenticationToken token, List <NameValuePair> nvps, File file)
    throws APIClientException {
		if (StringUtils.isEmpty(endpoint)) {
			throw new APIClientException("No endpoint provided");
		}
		if (token == null) {
			throw new APIClientException("No authenticatino token provided");
		}
		if (file == null) {
			throw new APIClientException("No file provided");
		} else if (!file.exists()) {
			throw new APIClientException("File does not exist.");
		}
		try {
        	Executor executor = Executor.newInstance()
        	        .auth(new HttpHost(Settings.SERVICE_BASE_URL), token.getUsername(), token.getToken());
        	String body = executor.execute(Request.Post(endpoint)
		            .version(HttpVersion.HTTP_1_1)
		            .useExpectContinue()
		            .bodyFile(file, ContentType.WILDCARD)
		            .bodyForm(nvps, Charset.defaultCharset()))
		            .returnContent().asString();
        	return new APIResponse(body);
        } 
        catch (APIClientException e) {
        	throw e;
        }
        catch (Exception e) {
        	throw new APIClientException("Failed to perform POST multipart file & form to " + endpoint, e);
        } 
    }
public APIResponse post ( String endpoint , AuthenticationToken token , List < NameValuePair > nvps , File file ) throws APIClientException { if ( StringUtils . isEmpty ( endpoint ) ) { throw new APIClientException ( "No endpoint provided" ) ; } if ( token == null ) { throw new APIClientException ( "No authenticatino token provided" ) ; } if ( file == null ) { throw new APIClientException ( "No file provided" ) ; } else if ( ! file . exists ( ) ) { throw new APIClientException ( "File does not exist." ) ; } try { Executor executor = Executor . newInstance ( ) . auth ( new HttpHost ( Settings . SERVICE_BASE_URL ) , token . getUsername ( ) , token . getToken ( ) ) ; String body = executor . execute ( Request . Post ( endpoint ) . version ( HttpVersion . HTTP_1_1 ) . useExpectContinue ( ) . bodyFile ( file , ContentType . WILDCARD ) . bodyForm ( nvps , Charset . defaultCharset ( ) ) ) . returnContent ( ) . asString ( ) ; return new APIResponse ( body ) ; } catch ( APIClientException e ) { throw e ; } catch ( Exception e ) { throw new APIClientException ( "Failed to perform POST multipart file & form to " + endpoint , e ) ; } }
Post a multipart form with file to the api.
Post a multipart form with file to the api .