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

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


    }

    public String uploadFile(String uri, String partName, String filename, String mimeType, byte[] contents, int expectedResponseCode) throws URISyntaxException, IOException {
        try (CloseableHttpClient client = HttpClients.createDefault()) {
            HttpPost post = new HttpPost(uri);
            ByteArrayBody contentBody = new ByteArrayBody(contents, ContentType.create(mimeType), filename);
            MultipartEntityBuilder builder = MultipartEntityBuilder.create();
            builder.addPart(partName, contentBody);
            post.setEntity(builder.build());
            HttpResponse response = client.execute(post);
            String result = EntityUtils.toString(response.getEntity());
View Full Code Here


            HttpPost post = new HttpPost(url);
            post.setHeader("Accept", MediaType.APPLICATION_JSON);
            MultipartEntity reqEntity = new MultipartEntity();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            IoUtil.write(fileStream(filePath), baos);
            reqEntity.addPart(elementName, new ByteArrayBody(baos.toByteArray(), "test_file"));
            post.setEntity(reqEntity);

            return new Response(post);
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

    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

    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

    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

    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

          throw new RuntimeException("failed to get the file key from CKAN storage form API. the response from " + formUrl + " was: " + os.toString());
        }
     
        //the file should be the last part
        //hack... StringBody didn't work with large files
        mpEntity.addPart("file", new ByteArrayBody(fileContent.getBytes(Charset.forName("UTF-8")),"multipart/form-data",fileLabel));

        postFile.setEntity(mpEntity);
     
        HttpResponse fileUploadResponse = client.execute(postFile);
     
View Full Code Here

      throw new RuntimeException("UTF-8 is not supported on this system; UTF-8 is required by the Java standard.", unsupportedEncodingException);
    }
  }

  public void addFileParam(String name, byte[] fileContents, final String fileName) {
    entity.addPart(name, new ByteArrayBody(fileContents, fileName));
  }
View Full Code Here

    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

        return addTextBody(name, text, ContentType.DEFAULT_TEXT);
    }

    public MultipartEntityBuilder addBinaryBody(
            final String name, final byte[] b, final ContentType contentType, final String filename) {
        return addPart(name, new ByteArrayBody(b, contentType, filename));
    }
View Full Code Here

TOP

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

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.