Package org.apache.http.entity.mime

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


        ByteArrayOutputStream out = new ByteArrayOutputStream();
        serializer.serialize(out, metadata, SupportedFormat.RDF_XML);
        String rdfContent = new String(out.toByteArray(),UTF8);
       
        //The multipart entity for the contentItem
        MultipartEntity contentItem = new MultipartEntity(null, null ,UTF8);
        //the "metadata" MUST BE the first element
        /*
         * NOTE: We need here to override the getFilename, because this MUST
         *       BE the URI of the ContentItem. This is important, because the
         *       Metadata do contain triples about that ContentItem and therefore
         *       it MUST BE assured that the URI of the ContentItem created by
         *       the Stanbol Enhancer is the same of as the URI used in the
         *       Metadata!
         */
        contentItem.addPart(
            "metadata", //the name MUST BE "metadata"
            new StringBody(rdfContent,SupportedFormat.RDF_XML,UTF8){
                @Override
                public String getFilename() { //The filename MUST BE the
                    return contentItemId.getUnicodeString(); //uri of the ContentItem
                }
            });
        //Add the Content
        /*
         * NOTE: If we only parse a single content than we can also directly
         *       add it with the name "content". This means that the useage of
         *       a "multipart/alternate" container is in such cases optional.
         */
        contentItem.addPart(
            "content", //the name MUST BE "content"
            new StringBody(HTML_CONTENT,"text/html",UTF8));
       
        //send the request
        String receivedContent = executor.execute(
View Full Code Here


    }

    @Before
    public void setupMultipart() {
        FileBody bin = new FileBody(file);
        multiPart = new MultipartEntity();
        multiPart.addPart(fileParam, bin);
    }
View Full Code Here

   
    @Test
    public void testPostMultipartConsistency409() throws Exception{
     
        FileBody bin = new FileBody(new File(URI.create(inconsistentFileName)));
        MultipartEntity incMultiPart = new MultipartEntity();
        incMultiPart.addPart(fileParam, bin);

      String[] services = {"/owl","/owlmini"};
  
      // Not consistent
      for(String s : services){
View Full Code Here

   * Call to create document
   */
  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);
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String response = client.execute(post, responseHandler);
View Full Code Here

   * Call to create folder
   */
  public static String createFolder(String token, String path, String url, File file) throws IOException {
    log.info("createFolder(" + token + ", " + path + ", " + url + ", " + file + ")");
    HttpClient client = new DefaultHttpClient();
    MultipartEntity form = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null, Charset.forName("UTF-8"));
    form.addPart("folder", new StringBody(file.getName(), Charset.forName("UTF-8")));
    form.addPart("path", new StringBody(path, Charset.forName("UTF-8")));
    form.addPart("action", new StringBody("2")); // FancyFileUpload.ACTION_FOLDER
    HttpPost post = new HttpPost(url + "/frontend/FileUpload;jsessionid=" + token);
    post.setHeader("Cookie", "jsessionid=" + token);
    post.setEntity(form);
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String response = client.execute(post, responseHandler);
View Full Code Here

      ios.close();
     
      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);
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        response = client.execute(post, responseHandler);
View Full Code Here

    return post(uri, linkIssuesInput, new LinkIssuesInputGenerator(getVersionInfo()));
  }

  @Override
  public Promise<Void> addAttachment(final URI attachmentsUri, final InputStream inputStream, final String filename) {
    final MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null, Charset.defaultCharset());
    entity.addPart(FILE_BODY_TYPE, new InputStreamBody(inputStream, filename));
    return postAttachments(attachmentsUri, entity);
  }
View Full Code Here

    return postAttachments(attachmentsUri, entity);
  }

  @Override
  public Promise<Void> addAttachments(final URI attachmentsUri, final AttachmentInput... attachments) {
    final MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null, Charset.defaultCharset());
    for (final AttachmentInput attachmentInput : attachments) {
      entity.addPart(FILE_BODY_TYPE, new InputStreamBody(attachmentInput.getInputStream(), attachmentInput.getFilename()));
    }
    return postAttachments(attachmentsUri, entity);
  }
View Full Code Here

    return postAttachments(attachmentsUri, entity);
  }

  @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

     */
    public File upload() throws UploadFailureException {
        URI uploadUrl = Urls.uploadBase();
        HttpPost request = new HttpPost(uploadUrl);

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

        String fileId = client.getRequestHelper().executeQuery(request, false, UploadBaseData.class).file;
        return client.getFile(fileId);
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.