public org . biouno . figshare . v1 . model . File uploadFile ( long articleId , File file ) { HttpClient httpClient = null ; try { final String method = String . format ( "my_data/articles/%d/files" , articleId ) ; // create an HTTP request to a protected resource final String url = getURL ( endpoint , version , method ) ; // create an HTTP request to a protected resource final HttpPut request = new HttpPut ( url ) ; MultipartEntityBuilder builder = MultipartEntityBuilder . create ( ) ; ContentBody body = new FileBody ( file ) ; FormBodyPart part = FormBodyPartBuilder . create ( "filedata" , body ) . build ( ) ; builder . addPart ( part ) ; HttpEntity entity = builder . build ( ) ; request . setEntity ( entity ) ; // sign the request consumer . sign ( request ) ; // send the request httpClient = HttpClientBuilder . create ( ) . build ( ) ; HttpResponse response = httpClient . execute ( request ) ; HttpEntity responseEntity = response . getEntity ( ) ; String json = EntityUtils . toString ( responseEntity ) ; org . biouno . figshare . v1 . model . File uploadedFile = readFileFromJson ( json ) ; return uploadedFile ; } catch ( OAuthCommunicationException e ) { throw new FigShareClientException ( "Failed to get articles: " + e . getMessage ( ) , e ) ; } catch ( OAuthMessageSignerException e ) { throw new FigShareClientException ( "Failed to get articles: " + e . getMessage ( ) , e ) ; } catch ( OAuthExpectationFailedException e ) { throw new FigShareClientException ( "Failed to get articles: " + e . getMessage ( ) , e ) ; } catch ( ClientProtocolException e ) { throw new FigShareClientException ( "Failed to get articles: " + e . getMessage ( ) , e ) ; } catch ( IOException e ) { throw new FigShareClientException ( "Failed to get articles: " + e . getMessage ( ) , e ) ; } }
Upload a file to an article .