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 4060700
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:22:18+00:00 2026-05-20T15:22:18+00:00

I have created a servlet that accepts an image from my android app.I am

  • 0

I have created a servlet that accepts an image from my android app.I am receiving bytes on my servlet, however, I want to be able to save this image with the original name on the server. How do I do that. I dont want to use apache commons. Is there any other solution that would work for me?

thanks

  • 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-05-20T15:22:18+00:00Added an answer on May 20, 2026 at 3:22 pm

    Send it as a multipart/form-data request with help of MultipartEntity class of Android’s builtin HttpClient API.

    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost("http://example.com/uploadservlet");
    MultipartEntity entity = new MultipartEntity();
    entity.addPart("fieldname", new InputStreamBody(fileContent, fileContentType, fileName));
    httpPost.setEntity(entity);
    HttpResponse servletResponse = httpClient.execute(httpPost);
    

    And then in servlet’s doPost() method, use Apache Commons FileUpload to extract the part.

    try {
        List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
        for (FileItem item : items) {
            if (item.getFieldName().equals("fieldname")) {
                String fileName = FilenameUtils.getName(item.getName());
                String fileContentType = item.getContentType();
                InputStream fileContent = item.getInputStream();
                // ... (do your job here)
            }
        }
    } catch (FileUploadException e) {
        throw new ServletException("Cannot parse multipart request.", e);
    }
    

    I dont want to use apache commons

    Unless you’re using Servlet 3.0 which supports multipart/form-data request out the box with HttpServletRequest#getParts(), you would need to reinvent a multipart/form-data parser yourself based on RFC2388. It’s only going to bite you on long term. Hard. I really don’t see any reasons why you wouldn’t use it. Is it plain ignorance? It’s at least not that hard. Just drop commons-fileupload.jar and commons-io.jar in /WEB-INF/lib folder and use the above example. That’s it. You can find here another example.

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

Sidebar

Related Questions

I have created a simple Servlet that I want to deploy in Jetty 7.2.
I have created a few small flash widgets that stream .mp3 audio from an
We have created a servlet that provides a FDF file for our clients. The
I installed on my Android phone a servlet container app with i-Jetty and created
I have created a PHP-script to update a web server that is live inside
I have created a UserControl that has a ListView in it. The ListView is
i have created a workflow activity that do give the item creater of a
I tried to deploy a servlet I have created to Glassfish application server, and
I have a use case where a servlet (that has reasonably high concurrent use)
I'm new to Servlet containers and have created a web application using Tomcat 6.0.26.

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.