Example usage for org.apache.http.entity.mime.content ContentBody getFilename

List of usage examples for org.apache.http.entity.mime.content ContentBody getFilename

Introduction

In this page you can find the example usage for org.apache.http.entity.mime.content ContentBody getFilename.

Prototype

String getFilename();

Source Link

Usage

From source file:com.linkedin.pinot.common.utils.FileUploadDownloadClient.java

private static HttpUriRequest getUploadFileRequest(String method, URI uri, ContentBody contentBody,
        @Nullable List<Header> headers, @Nullable List<NameValuePair> parameters, int socketTimeoutMs) {
    // Build the Http entity
    HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
            .addPart(contentBody.getFilename(), contentBody).build();

    // Build the request
    RequestBuilder requestBuilder = RequestBuilder.create(method).setVersion(HttpVersion.HTTP_1_1).setUri(uri)
            .setEntity(entity);/*from ww  w.jav a2s  .  c  o m*/
    addHeadersAndParameters(requestBuilder, headers, parameters);
    setTimeout(requestBuilder, socketTimeoutMs);
    return requestBuilder.build();
}

From source file:ch.cyberduck.core.dropbox.client.DropboxClient.java

/**
 * Put a file in the user's Dropbox./*from w  w  w. jav a2  s  .  c om*/
 */
public void put(String to, ContentBody content) throws IOException {
    HttpClient client = getClient();

    HttpPost req = (HttpPost) buildRequest(HttpPost.METHOD_NAME, "/files/" + ROOT + to, true);

    // this has to be done this way because of how oauth signs params
    // first we add a "fake" param of file=path of *uploaded* file, THEN we sign that.
    List<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>();
    nvps.add(new BasicNameValuePair("file", content.getFilename()));
    req.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
    try {
        auth.sign(req);
    } catch (OAuthException e) {
        IOException failure = new IOException(e.getMessage());
        failure.initCause(e);
        throw failure;
    }
    // now we can add the real file multipart and we're good
    MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    entity.addPart("file", content);

    // this resets it to the new entity with the real file
    req.setEntity(entity);

    this.finish(client.execute(req));
}