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

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


            String uri = DefaultServer.getDefaultServerURL() + "/servletContext/3";
            HttpPost post = new HttpPost(uri);
            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(MultiPartTestCase.class.getResource("uploadfile.txt").getFile())));

            post.setEntity(entity);
            HttpResponse result = client.execute(post);
            String response = HttpClientUtils.readResponse(result);
            Assert.assertEquals("TEST FAILED: wrong response code\n" + response, 500, result.getStatusLine().getStatusCode());
View Full Code Here


    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) {
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

            final String name, final File file, final ContentType contentType, final String filename) {
        if (this.bodyParts == null) {
            this.bodyParts = new ArrayList<FormBodyPart>();
        }
        this.bodyParts.add(
                new FormBodyPart(name, new FileBody(file, contentType, filename)));
        return this;
    }
View Full Code Here

        }

        final HttpMultipart multipart = new HttpMultipart("form-data", "foo");
        final FormBodyPart p1 = new FormBodyPart(
                "field1",
                new FileBody(tmpfile));
        final FormBodyPart p2 = new FormBodyPart(
                "field2",
                new InputStreamBody(new FileInputStream(tmpfile), "file.tmp"));

        multipart.addBodyPart(p1);
View Full Code Here

        }

        final HttpMultipart multipart = new HttpMultipart("form-data", null, "foo", HttpMultipartMode.STRICT);
        final FormBodyPart p1 = new FormBodyPart(
                "field1",
                new FileBody(tmpfile));
        final FormBodyPart p2 = new FormBodyPart(
                "field2",
                new FileBody(tmpfile, ContentType.create("text/plain", "ANSI_X3.4-1968"), "test-file"));
        final FormBodyPart p3 = new FormBodyPart(
                "field3",
                new InputStreamBody(new FileInputStream(tmpfile), "file.tmp"));

        multipart.addBodyPart(p1);
View Full Code Here

            writer.close();
        }

        final FormBodyPart p1 = new FormBodyPart(
                "field1",
                new FileBody(tmpfile));
        final FormBodyPart p2 = new FormBodyPart(
                "field2",
                new InputStreamBody(new FileInputStream(tmpfile), "file.tmp"));
        final HttpStrictMultipart multipart = new HttpStrictMultipart("form-data", null, "foo",
                Arrays.asList(p1, p2));
View Full Code Here

            writer.close();
        }

        final FormBodyPart p1 = new FormBodyPart(
                "field1",
                new FileBody(tmpfile));
        final FormBodyPart p2 = new FormBodyPart(
                "field2",
                new FileBody(tmpfile, ContentType.create("text/plain", "ANSI_X3.4-1968"), "test-file"));
        final FormBodyPart p3 = new FormBodyPart(
                "field3",
                new InputStreamBody(new FileInputStream(tmpfile), "file.tmp"));
        final HttpStrictMultipart multipart = new HttpStrictMultipart("form-data", null, "foo",
                Arrays.asList(p1, p2, p3));
View Full Code Here

            writer.close();
        }

        final FormBodyPart p1 = new FormBodyPart(
                "field1\u0414",
                new FileBody(tmpfile));
        final FormBodyPart p2 = new FormBodyPart(
                "field2",
                new FileBody(tmpfile, ContentType.create("text/plain", "ANSI_X3.4-1968"), "test-file"));
        final FormBodyPart p3 = new FormBodyPart(
                "field3",
                new InputStreamBody(new FileInputStream(tmpfile), "file.tmp"));
        final HttpRFC6532Multipart multipart = new HttpRFC6532Multipart("form-data", null, "foo",
                Arrays.asList(p1, p2, p3));
View Full Code Here

        return addBinaryBody(name, b, ContentType.DEFAULT_BINARY, null);
    }

    public MultipartEntityBuilder addBinaryBody(
            final String name, final File file, final ContentType contentType, final String filename) {
        return addPart(name, new FileBody(file, contentType, filename));
    }
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.