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

  • Home
  • SEARCH
  • 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 8784773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:11:19+00:00 2026-06-13T21:11:19+00:00

I am trying to create a file upload web service which also needs a

  • 0

I am trying to create a file upload web service which also needs a few string also to be passed as parameters as a small part of my project…

So far I have managed to create a file upload web-service. But it works only when I am passing only files to be uploaded as input. Now I modified the web-service to accept few parameters as well. But it is giving me error :

java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern – For input string: “&'”

I dint copy the entire stacktrace here I feel it would me pointless.
This is my web service :

    @POST 
@Path("/postdata") 
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void postData3(List<Attachment> atts, @FormParam("username") final String username, @Context HttpServletRequest request)
{
    System.out.println(username);
    String home = "/home/yashdosi/s";
    for(Attachment att : atts)
    {
        DataHandler dataHandler = att.getDataHandler();
        try 
        {
            InputStream stream = dataHandler.getInputStream();
            MultivaluedMap map = att.getHeaders();
            OutputStream out = new FileOutputStream(new File(home + "//" + getFileName(map)));

            int read = 0;
            byte[] bytes = new byte[1024];
            while ((read = stream.read(bytes)) != -1) {
                out.write(bytes, 0, read);
            }
            stream.close();
            out.flush();
            out.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

And this is my Java Client :

        HttpClient httpclient = new DefaultHttpClient();
    try {
        HttpPost httppost = new HttpPost("http://localhost:8080/fileupload-ws/services/postdata");

        FileBody img = new FileBody(new File("/home/yashdosi/1.jpg"));
        FileBody html = new FileBody(new File("/home/yashdosi/hotmail.html"));
        StringBody contentBody = new StringBody("some.email@gmail.com");

        MultipartEntity reqEntity = new MultipartEntity();
        reqEntity.addPart("image", img);
        reqEntity.addPart("html", html);
        reqEntity.addPart("username", contentBody);

        httppost.setEntity(reqEntity);
        //httppost.setHeader("Content-Type", "multipart/form-data");

        System.out.println("executing request " + httppost.getRequestLine());
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();

        System.out.println("----------------------------------------");
        System.out.println(response.getStatusLine());
        if (resEntity != null) {
            System.out.println("Response content length: " + resEntity.getContentLength());
        }
        EntityUtils.consume(resEntity);
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    finally {
        try { httpclient.getConnectionManager().shutdown(); } catch (Exception ignore) {}
    }

Any ideas what is causing this error?
Or how I should get around this problem!?

  • 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-13T21:11:21+00:00Added an answer on June 13, 2026 at 9:11 pm

    Try using @MultiPart(value="image") for image, @MultiPart(value="html") for html and @MultiPart(value="username") for content body. Worked for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to Upload video File .mov to remote web service from my
I am trying to create a PHP file to upload images to my website.
I am trying to upload a file with playframework. I create a form and
I'm trying to create a custom file upload control in WPF 4.0 and I'm
I'm trying to create a web service for my existing java project. In my
I am trying to create a file upload field that has a little bit
I am writing a small file upload utility thing as part of a larger
I am trying to create a simple screen where the file selected for upload
I am trying to create a multiple file upload flash application to be called
well I'm trying to upload a file to my servlet from the web interface.

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.