Package org.apache.http.entity.mime.content

Examples of org.apache.http.entity.mime.content.FileBody


   */
  public static String createDocument(String token, String path, String url, File file) throws IOException {
    log.info("createDocument(" + token + ", " + path + ", " + url + ", " + file + ")");
    HttpClient client = new DefaultHttpClient();
    MultipartEntity form = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null, Charset.forName("UTF-8"));
    form.addPart("file", new FileBody(file));
    form.addPart("path", new StringBody(path, Charset.forName("UTF-8")));
    form.addPart("action", new StringBody("0")); // FancyFileUpload.ACTION_INSERT
    HttpPost post = new HttpPost(url + "/frontend/FileUpload;jsessionid=" + token);
    post.setHeader("Cookie", "jsessionid=" + token);
    post.setEntity(form);
View Full Code Here


     
      if (token != null) {
        // Send image
        HttpClient client = new DefaultHttpClient();
        MultipartEntity form = new MultipartEntity();
        form.addPart("file", new FileBody(tmpFile));
        form.addPart("path", new StringBody(path, Charset.forName("UTF-8")));
        form.addPart("action", new StringBody("0")); // FancyFileUpload.ACTION_INSERT
        HttpPost post = new HttpPost(url + "/frontend/FileUpload;jsessionid=" + token);
        post.setHeader("Cookie", "jsessionid=" + token);
        post.setEntity(form);
View Full Code Here

  @Override
  public Promise<Void> addAttachments(final URI attachmentsUri, final File... files) {
    final MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null, Charset.defaultCharset());
    for (final File file : files) {
      entity.addPart(FILE_BODY_TYPE, new FileBody(file));
    }
    return postAttachments(attachmentsUri, entity);
  }
View Full Code Here

        MultipartEntity entity = new MultipartEntity();
        StringBody pubKeyBody = StringBody.create(client.getPublicKey(), "text/plain", null);
        entity.addPart("UPLOADCARE_PUB_KEY", pubKeyBody);
        if (file != null) {
            entity.addPart("file", new FileBody(file));
        } else {
            entity.addPart("file", new ByteArrayBody(bytes, filename));
        }
        request.setEntity(entity);
View Full Code Here

    if (hasFile) {
      MultipartEntityBuilder builder = MultipartEntityBuilder.create();
      for(String key: keyOrder) {
        Object value = parameters.get(key);
        if (value instanceof File) {
          builder.addPart(key, new FileBody((File) value));
        } else {
          builder.addPart(key, new StringBody(value.toString(), ContentType.create(ContentType.APPLICATION_FORM_URLENCODED.getMimeType(), Charset.forName(UTF_8))));
        }
      }
      return builder.build();
View Full Code Here

       
        HttpMultipart multipart = new HttpMultipart();
        multipart.setParent(message);
        FormBodyPart p1 = new FormBodyPart(
                "field1",
                new FileBody(tmpfile));
        FormBodyPart p2 = new FormBodyPart(
                "field2",
                new InputStreamBody(new FileInputStream(tmpfile), "file.tmp"));
       
        multipart.addBodyPart(p1);
View Full Code Here

  @Override
  public Promise<Void> addAttachments(final URI attachmentsUri, final File... files) {
    final MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null, Charset.defaultCharset());
    for (final File file : files) {
      entity.addPart(FILE_BODY_TYPE, new FileBody(file));
    }
    return postAttachments(attachmentsUri, entity);
  }
View Full Code Here

  @Override
  public Promise<Void> addAttachments(final URI attachmentsUri, final File... files) {
    final MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    for (final File file : files) {
      entity.addPart(FILE_BODY_TYPE, new FileBody(file));
    }
    return postAttachments(attachmentsUri, entity);
  }
View Full Code Here

            HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/path");
            //post.setHeader(Headers.CONTENT_TYPE, MultiPartHandler.MULTIPART_FORM_DATA);
            MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

            entity.addPart("formValue", new StringBody("myValue", "text/plain", Charset.forName("UTF-8")));
            entity.addPart("file", new FileBody(new File(MultipartFormDataParserTestCase.class.getResource("uploadfile.txt").getFile())));

            post.setEntity(entity);
            HttpResponse result = client.execute(post);
            Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
            HttpClientUtils.readResponse(result);
View Full Code Here

            HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/path");
            //post.setHeader(Headers.CONTENT_TYPE, MultiPartHandler.MULTIPART_FORM_DATA);
            MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

            entity.addPart("formValue", new StringBody("myValue", "text/plain", Charset.forName("UTF-8")));
            entity.addPart("file", new FileBody(new File(MultipartFormDataParserTestCase.class.getResource("uploadfile.txt").getFile())));

            post.setEntity(entity);
            HttpResponse result = client.execute(post);
            Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
            HttpClientUtils.readResponse(result);
View Full Code Here

TOP

Related Classes of org.apache.http.entity.mime.content.FileBody

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.