Examples of MultipartEntityBuilder


Examples of org.apache.http.entity.mime.MultipartEntityBuilder

   */
  public Result<NewT> addPicT(String accessToken, String oauthConsumerKey, String openId,
      String content, byte[] pic, String clientIp, Double lon, Double lat, Boolean sync,
      Boolean compatible) {
    HttpPost request = new HttpPost("https://graph.qq.com/t/add_pic_t");
    MultipartEntityBuilder builder = MultipartEntityBuilder.create().addBinaryBody("pic", pic);

    List<NameValuePair> params = new ArrayList<NameValuePair>();
    addParameter(params, "access_token", accessToken);
    addParameter(params, "oauth_consumer_key", oauthConsumerKey);
    addParameter(params, "openid", openId);
    addParameter(params, "content", content);
    addNotNullParameter(params, "clientip", clientIp);
    addNotNullParameter(params, "lon", lon);
    addNotNullParameter(params, "lat", lat);
    if (sync != null) {
      addParameter(params, "syncflag", sync ? "0" : "1");
    }
    if (compatible != null) {
      addParameter(params, "compatibleflag", compatible ? "0" : "0x20");
    }
    addParameter(params, "format", "json");

    for (NameValuePair nameValuePair : params) {
      builder.addTextBody(nameValuePair.getName(), nameValuePair.getValue());
    }
    request.setEntity(builder.build());
    try {
      HttpResponse response = Http.CLIENT.execute(request);
      String json = IOUtils.toString(response.getEntity().getContent());
      JSONObject jsonObject = new JSONObject(json);
      Error error = Error.parse(jsonObject);
View Full Code Here

Examples of org.apache.http.entity.mime.MultipartEntityBuilder

public class HttpMultipartHelper {

  public static HttpEntity getMultiPartEntity(String fileName, String contentType, InputStream fileStream,
      Map<String, String> additionalFormFields) throws IOException {
   
    MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
   
    if (additionalFormFields != null && !additionalFormFields.isEmpty()) {
      for (Entry<String, String> field : additionalFormFields.entrySet()) {
        entityBuilder.addTextBody(field.getKey(), field.getValue());
      }
    }
   
    entityBuilder.addBinaryBody(fileName, IOUtils.toByteArray(fileStream), ContentType.create(contentType), fileName);
   
    return entityBuilder.build();
  }
View Full Code Here

Examples of org.apache.http.entity.mime.MultipartEntityBuilder

        final URL url = Thread.currentThread().getContextClassLoader().getResource("uploads/" + TEXTFILENAME);
        final File file = new File(url.getPath());
        final FileBody fileBody = new FileBody(file, ContentType.DEFAULT_BINARY);
        final StringBody stringBody1 = new StringBody("This is message 1", ContentType.MULTIPART_FORM_DATA);
        final StringBody stringBody2 = new StringBody("This is message 2", ContentType.MULTIPART_FORM_DATA);
        final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        builder.addPart("upfile", fileBody);
        builder.addPart("text1", stringBody1);
        builder.addPart("text2", stringBody2);
        final HttpEntity entity = builder.build();
        post.setEntity(entity);
        response = client.execute(post);
        final int statusCode = response.getStatusLine().getStatusCode();
        final String responseString = getContent();
        final String contentTypeInHeader = getContentTypeHeader();
View Full Code Here

Examples of org.apache.http.entity.mime.MultipartEntityBuilder

    @Test
    public final void givenFileandTextPart_whenUploadwithAddBinaryBodyandAddTextBody_ThenNoExeption() throws ClientProtocolException, IOException {
        final URL url = Thread.currentThread().getContextClassLoader().getResource("uploads/" + TEXTFILENAME);
        final File file = new File(url.getPath());
        final String message = "This is a multipart post";
        final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        builder.addBinaryBody("upfile", file, ContentType.DEFAULT_BINARY, TEXTFILENAME);
        builder.addTextBody("text", message, ContentType.DEFAULT_BINARY);
        final HttpEntity entity = builder.build();
        post.setEntity(entity);
        response = client.execute(post);
        final int statusCode = response.getStatusLine().getStatusCode();
        final String responseString = getContent();
        final String contentTypeInHeader = getContentTypeHeader();
View Full Code Here

Examples of org.apache.http.entity.mime.MultipartEntityBuilder

        final URL url = Thread.currentThread().getContextClassLoader().getResource("uploads/" + ZIPFILENAME);
        final URL url2 = Thread.currentThread().getContextClassLoader().getResource("uploads/" + IMAGEFILENAME);
        final InputStream inputStream = new FileInputStream(url.getPath());
        final File file = new File(url2.getPath());
        final String message = "This is a multipart post";
        final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        builder.addBinaryBody("upfile", file, ContentType.DEFAULT_BINARY, IMAGEFILENAME);
        builder.addBinaryBody("upstream", inputStream, ContentType.create("application/zip"), ZIPFILENAME);
        builder.addTextBody("text", message, ContentType.TEXT_PLAIN);
        final HttpEntity entity = builder.build();
        post.setEntity(entity);
        response = client.execute(post);
        final int statusCode = response.getStatusLine().getStatusCode();
        final String responseString = getContent();
        final String contentTypeInHeader = getContentTypeHeader();
View Full Code Here

Examples of org.apache.http.entity.mime.MultipartEntityBuilder

    @Test
    public final void givenCharArrayandText_whenUploadwithAddBinaryBodyandAddTextBody_ThenNoException() throws ClientProtocolException, IOException {
        final String message = "This is a multipart post";
        final byte[] bytes = "binary code".getBytes();
        final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        builder.addBinaryBody("upfile", bytes, ContentType.DEFAULT_BINARY, TEXTFILENAME);
        builder.addTextBody("text", message, ContentType.TEXT_PLAIN);
        final HttpEntity entity = builder.build();
        post.setEntity(entity);
        response = client.execute(post);
        final int statusCode = response.getStatusLine().getStatusCode();
        final String responseString = getContent();
        final String contentTypeInHeader = getContentTypeHeader();
View Full Code Here

Examples of org.apache.http.entity.mime.MultipartEntityBuilder

    this.password = password;
  }

  public Result<String> decode(byte[] img, YundamaType type) {
    HttpPost request = new HttpPost("http://api.yundama.com/api.php?method=upload");
    MultipartEntityBuilder builder =
        MultipartEntityBuilder.create()
            .addBinaryBody("file", img, ContentType.create("image/png"), "code.png")
            .addTextBody("username", username).addTextBody("password", password)
            .addTextBody("codetype", type.getType().toString()).addTextBody("appid", appId)
            .addTextBody("appkey", appKey).addTextBody("timeout", "60");
    request.setEntity(builder.build());
    try {
      HttpResponse response = Http.CLIENT.execute(request);
      String json = IOUtils.toString(response.getEntity().getContent());
      request.releaseConnection();
      JSONObject jsonObject = new JSONObject(json);
View Full Code Here

Examples of org.apache.http.entity.mime.MultipartEntityBuilder

      com.belerweb.social.weixin.bean.Media media) {
    String url =
        "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=" + accessToken + "&type="
            + type.value();
    HttpPost request = new HttpPost(url);
    MultipartEntityBuilder builder =
        MultipartEntityBuilder.create().addBinaryBody("media", media.getContent(),
            ContentType.create(media.getContentType()), media.getName());
    request.setEntity(builder.build());
    try {
      HttpResponse response = Http.CLIENT.execute(request);
      String json = IOUtils.toString(response.getEntity().getContent());
      JSONObject jsonObject = new JSONObject(json);
      Error error = Error.parse(jsonObject);
View Full Code Here

Examples of org.apache.http.entity.mime.MultipartEntityBuilder

        nameValuePairList.add(new BasicNameValuePair( "policy""eyJleHBpcmF0aW9uIjogIjIwMTMtMTItMjNUMDk6MjQ6MThaIiwKImNvbmRpdGlvbnMiOiBbeyJ4LWdvb2ctbWV0YS11cGxvYWRlZC1ieSI6ICIzYmFlNDAxMy1kMDNlLTQyN2ItYWMyZS05ZTVkMDg0ZDBlYTkifSx7ImJ1Y2tldCI6ICJja2FubmV0LXN0b3JhZ2UifSx7ImtleSI6ICIyMDEzLTEyLTIyVDEzOjI0OjEyLjg1M1ovdGVzdC54bWwifSx7ImFjbCI6ICJwdWJsaWMtcmVhZCJ9LHsic3VjY2Vzc19hY3Rpb25fcmVkaXJlY3QiOiAiaHR0cDovL2RhdGFodWIuaW8vc3RvcmFnZS91cGxvYWQvc3VjY2Vzc19lbXB0eT9sYWJlbD0yMDEzLTEyLTIyVDEzJTNBMjQlM0ExMi44NTNaJTJGdGVzdC54bWwifSxbImNvbnRlbnQtbGVuZ3RoLXJhbmdlIiwgMCwgMTAwMDAwMDAwMDBdXX0="));
        nameValuePairList.add(new BasicNameValuePair( "GoogleAccessId""GOOGC6OU3AYPNY47B66M"));
        nameValuePairList.add(new BasicNameValuePair( "signature""VFYngO/4ZQRYt4YXnRGXitiJyNE="));
        nameValuePairList.add(new BasicNameValuePair( "key""2013-12-22T13:24:12.853Z/test97.xml"));

        MultipartEntityBuilder multipartEntityBuilder =
            MultipartEntityBuilder.create();
       
        multipartEntityBuilder.addBinaryBody("test", new File("src/test/resources/org/xmlcml/ckan/test.xml"));
       
        HttpEntity entity = multipartEntityBuilder.build();
        httpPost.setEntity(entity);
       
      //Send request
   
      HttpResponse httpResponse = httpClient.execute(httpPost);
View Full Code Here

Examples of org.apache.http.entity.mime.MultipartEntityBuilder

        nameValuePairList.add(new BasicNameValuePair( "policy""eyJleHBpcmF0aW9uIjogIjIwMTMtMTItMjNUMDk6MjQ6MThaIiwKImNvbmRpdGlvbnMiOiBbeyJ4LWdvb2ctbWV0YS11cGxvYWRlZC1ieSI6ICIzYmFlNDAxMy1kMDNlLTQyN2ItYWMyZS05ZTVkMDg0ZDBlYTkifSx7ImJ1Y2tldCI6ICJja2FubmV0LXN0b3JhZ2UifSx7ImtleSI6ICIyMDEzLTEyLTIyVDEzOjI0OjEyLjg1M1ovdGVzdC54bWwifSx7ImFjbCI6ICJwdWJsaWMtcmVhZCJ9LHsic3VjY2Vzc19hY3Rpb25fcmVkaXJlY3QiOiAiaHR0cDovL2RhdGFodWIuaW8vc3RvcmFnZS91cGxvYWQvc3VjY2Vzc19lbXB0eT9sYWJlbD0yMDEzLTEyLTIyVDEzJTNBMjQlM0ExMi44NTNaJTJGdGVzdC54bWwifSxbImNvbnRlbnQtbGVuZ3RoLXJhbmdlIiwgMCwgMTAwMDAwMDAwMDBdXX0="));
        nameValuePairList.add(new BasicNameValuePair( "GoogleAccessId""GOOGC6OU3AYPNY47B66M"));
        nameValuePairList.add(new BasicNameValuePair( "signature""VFYngO/4ZQRYt4YXnRGXitiJyNE="));
        nameValuePairList.add(new BasicNameValuePair( "key""2013-12-22T13:24:12.853Z/test97.xml"));

        MultipartEntityBuilder multipartEntityBuilder =
            MultipartEntityBuilder.create();
       
        multipartEntityBuilder.addBinaryBody("test", new File("src/test/resources/org/xmlcml/ckan/test.xml"));
        for (NameValuePair nvp : nameValuePairList) {
          multipartEntityBuilder.addTextBody(nvp.getName(),  nvp.getValue());
        }
       
        HttpEntity entity = multipartEntityBuilder.build();
        LOG.debug("entity "+entity.getClass()+entity.getContentLength());
       
      httpPut.setEntity(new UrlEncodedFormEntity(nameValuePairList));
        httpPut.setEntity(entity);
       
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.