Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8003335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:37:28+00:00 2026-06-04T16:37:28+00:00

I would like to POST (in Java) a multipart/mixed request, where one part is

  • 0

I would like to POST (in Java) a multipart/mixed request, where one part is of type ‘application/json’ and the other of type ‘application/pdf’. Does anyone know of a library which will allow me to do this easily? Surprisingly I haven’t been able to find one.

I’ll generate the JSON, but I need to be able to set the content type of that part to ‘application/json’.

Many thanks,
Daniel

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:37:29+00:00Added an answer on June 4, 2026 at 4:37 pm

    Easy, use the Apache Http-client library (this code used version 4.1 and the jars httpclient, httpcore and httpmime), here’s a sample:

    package com.officedrop.uploader;
    
    import java.io.File;
    import java.net.URL;
    
    import org.apache.http.HttpHost;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.entity.mime.HttpMultipartMode;
    import org.apache.http.entity.mime.MultipartEntity;
    import org.apache.http.entity.mime.content.FileBody;
    import org.apache.http.impl.client.DefaultHttpClient;
    
    public class SampleUploader {
    
        public static void main(String[] args) throws Exception {
    
            DefaultHttpClient httpclient = new DefaultHttpClient();
            String basePath = "http://localhost/";
    
            URL url = new URL( basePath );
    
            HttpHost targetHost = new HttpHost( url.getHost(), url.getPort(), url.getProtocol() );  
    
            HttpPost httpost = new HttpPost( String.format( "%s%s", basePath, "ze/api/documents.xml"));
    
            MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    
            entity.addPart("file_1", new FileBody( new File( "path-to-file.pdf" ) , "file.pdf", "application/pdf", null));
            entity.addPart("uploaded_data_1", new FileBody( new File( "path-to-file.json" ) , "file.json", "application/json", null));    
    
            httpost.setEntity(entity);
    
            HttpResponse response = httpclient.execute( targetHost, httpost);
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to send a POST request in Java. At the moment, I
I've generate an HTMLPost Request containing a JSON object in java and would like
I would like to know how to send a post request in curl and
I would like to change url the HTTP POST to during the request in
I would like to POST an entity as follows POST /example.org/MyEntity/100 Based on the
I would like to POST data from my Windows Phone to a webpage that
I would like to get POST data sent to page controller in init() function
I have a custom posttype in Wordpress 3. I would like to every post
i would like an index action to be able to take get and post
This post identifies a feature that I would like to disable. Current numpy behavior:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.