Package org.apache.http.entity.mime

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


      throw new IOException(javascript.getAbsolutePath() + " does not exist");
    }
   
    HttpPost request = new HttpPost(uri + "/post/structure");

    MultipartEntity requestEntity = new MultipartEntity();
    FileBody bin1 = new FileBody(formStructure, "application/xml; charset=\"UTF-8\"");
    FileBody bin2 = null;
    requestEntity.addPart("xml", bin1);
    if (javascript != null) {
      bin2 = new FileBody(javascript, "text/javascript; charset=\"UTF-8\"");
      requestEntity.addPart("js", bin2);
    }
     
    request.setEntity(requestEntity);
       
    HttpResponse response = httpclient.execute(request);
View Full Code Here


    @Test
    public void testMultipartRequestToDefaultServlet() throws Exception {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        try {
            HttpPost post = new HttpPost(url.toExternalForm() + "/servlet");
            MultipartEntity mp = new MultipartEntity();
            mp.addPart("file", new StringBody(MESSAGE));
            post.setEntity(mp);

            HttpResponse response = httpclient.execute(post);
            HttpEntity entity = response.getEntity();
View Full Code Here

    }

    public void makeMultiPart() {
        if (!multiPart) {
            multiPart = true;
            multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        }
    }
View Full Code Here

      Map<String, String> newHeaders ) throws Exception
  {
    HttpPost post = new HttpPost(url.toURI());

    setupMethod(post, newHeaders);
    MultipartEntity entity = new MultipartEntity();

    InputStreamBody body = new InputStreamBody(content, filename);

    entity.addPart("file", body);
    post.setEntity(entity);
    HttpResponse response = execute(post);
    if (responseClass == null || response.getEntity() == null)
    {
      EntityUtils.consumeQuietly(response.getEntity());
View Full Code Here

        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(mApiUrl + ApiConstants.METHOD_ATTACHMENTS + ".xml");

        FileBody bin = new FileBody(new File(fileToUpload));
        try {
            MultipartEntity reqEntity = new MultipartEntity();
            reqEntity.addPart("attachment[file]", bin);
            reqEntity.addPart("attachment[app_id]", new StringBody(appId));
            reqEntity.addPart("attachment[comment]", new StringBody(comment));
            reqEntity.addPart("attachment[type]", new StringBody(type));
            httppost.setEntity(reqEntity);

            HttpResponse response = httpclient.execute(httppost);
            HttpEntity resEntity = response.getEntity();
            return resEntity.getContent();
View Full Code Here

            if(contentEncoding != null) {
                charset = Charset.forName(contentEncoding);
            }

            // Write the request to our own stream
            MultipartEntity multiPart = new MultipartEntity(
                    getDoBrowserCompatibleMultipart() ? HttpMultipartMode.BROWSER_COMPATIBLE : HttpMultipartMode.STRICT,
                            null, charset);
            // Create the parts
            // Add any parameters
            PropertyIterator args = getArguments().iterator();
            while (args.hasNext()) {
               HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
               String parameterName = arg.getName();
               if (arg.isSkippable(parameterName)){
                   continue;
               }
               FormBodyPart formPart;
               StringBody stringBody = new StringBody(arg.getValue(),
                       Charset.forName(contentEncoding == null ? "US-ASCII" : contentEncoding));
               formPart = new FormBodyPart(arg.getName(), stringBody);                  
               multiPart.addPart(formPart);
            }

            // Add any files
            // Cannot retrieve parts once added to the MultiPartEntity, so have to save them here.
            ViewableFileBody[] fileBodies = new ViewableFileBody[files.length];
            for (int i=0; i < files.length; i++) {
                HTTPFileArg file = files[i];
                fileBodies[i] = new ViewableFileBody(new File(file.getPath()), file.getMimeType());
                multiPart.addPart(file.getParamName(),fileBodies[i]);
            }

            post.setEntity(multiPart);

            if (multiPart.isRepeatable()){
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                for(ViewableFileBody fileBody : fileBodies){
                    fileBody.hideFileData = true;
                }
                multiPart.writeTo(bos);
                for(ViewableFileBody fileBody : fileBodies){
                    fileBody.hideFileData = false;
                }
                bos.flush();
                // We get the posted bytes using the encoding used to create it
View Full Code Here

                           content.getName())));
                }
              }
             
              if (parts.size() > 0) {
                MultipartEntity entity = new MultipartEntity(HttpMultipartMode.STRICT);
                for(FormBodyPart p: parts) {
                  entity.addPart(p);
                }
                post.setEntity(entity);
              } else {
                //not using multipart
                post.setEntity(new UrlEncodedFormEntity(postParams, "UTF-8"));
View Full Code Here

                "/servlets-examples/servlet/RequestInfoExample");

        FileBody bin = new FileBody(new File(args[0]));
        StringBody comment = new StringBody("A binary file of some kind");

        MultipartEntity reqEntity = new MultipartEntity();
        reqEntity.addPart("bin", bin);
        reqEntity.addPart("comment", comment);
       
        httppost.setEntity(reqEntity);
       
        System.out.println("executing request " + httppost.getRequestLine());
        HttpResponse response = httpclient.execute(httppost);
View Full Code Here

                "/servlets-examples/servlet/RequestInfoExample");

        FileBody bin = new FileBody(new File(args[0]));
        StringBody comment = new StringBody("A binary file of some kind");

        MultipartEntity reqEntity = new MultipartEntity();
        reqEntity.addPart("bin", bin);
        reqEntity.addPart("comment", comment);
       
        httppost.setEntity(reqEntity);
       
        System.out.println("executing request " + httppost.getRequestLine());
        HttpResponse response = httpclient.execute(httppost);
View Full Code Here

    String apiUrl = cloudinary.cloudinaryApiUrl(action, options);

    HttpClient client = new DefaultHttpClient();

    HttpPost postMethod = new HttpPost(apiUrl);
    MultipartEntity multipart = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    // Remove blank parameters
    for (Map.Entry<String, Object> param : params.entrySet()) {
      if (param.getValue() instanceof String) {
        String value = (String) param.getValue();
        if (StringUtils.isNotBlank(value)) {
          multipart.addPart(param.getKey(), new StringBody(value));
        }
      } else if (param.getValue() instanceof Collection) {
        for (Object value : (Collection) param.getValue()) {
          multipart.addPart(param.getKey()+"[]", new StringBody(Cloudinary.asString(value)));         
        }
      }
    }

    if (file instanceof String && !((String) file).matches("https?:.*|s3:.*|data:[^;]*;base64,([a-zA-Z0-9/+\n=]+)")) {
      file = new File((String) file);
    }
    if (file instanceof File) {
      multipart.addPart("file", new FileBody((File) file));
    } else if (file instanceof String) {
      multipart.addPart("file", new StringBody((String) file));
        } else if (file instanceof byte[]) {
            multipart.addPart("file", new ByteArrayBody((byte[]) file, "file"));
    } else if (file == null) {
        // no-problem
    } else {
        throw new IOException("Uprecognized file parameter " + file);
    }
View Full Code Here

TOP

Related Classes of org.apache.http.entity.mime.MultipartEntity

Copyright © 2018 www.massapicom. 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.