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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:12:17+00:00 2026-05-20T21:12:17+00:00

I have a simple form with an option to upload image but to upload

  • 0

I have a simple form with an option to upload image but to upload a file I am not using this method

<form:input path="logoData" id="image" type="file" />

instead I am using ajax upload jquery pulgin.
The problem is upload.parseRequest(request) is returning null in the below code :

@RequestMapping(value = "/upload.htm", method = RequestMethod.POST)
public @ResponseBody String upload(HttpServletRequest request) throws FileUploadException{

    // Create a factory for disk-based file items
    FileItemFactory factory = new DiskFileItemFactory();

    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload(factory);

    // Parse the request
    List<FileItem> items = upload.parseRequest(request);
     System.out.println("====ITEMS====" + items.size());


     System.out.println("----REQUEST---" +request.getParameter("uploadImg"));
        System.out.println("-----SIZE----" +request.getParameterMap().size());
        Map<String, String> map = request.getParameterMap();

        for(Map.Entry<String, String> entry : map.entrySet()){
            System.out.println("----KEY---" + entry.getKey() + "----value---" + entry.getValue());
        }


 // Check that we have a file upload request
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);

    System.out.println("----IS MULTIPART---" +isMultipart);
    return "hello";
}

Output of log is :

====ITEMS====0
—-REQUEST—null
—–SIZE—-0
—-IS MULTIPART—true

And my javascript code is :

new AjaxUpload('#upload', {
action : my_url+ 'methodName/upload.htm',
name : 'uploadImg',
autoSubmit : true,
responseType: 'html',
onChange: function(file, extension){   },   
onSubmit: function(file, extension) {

},
onComplete: function(file, html) {
    alert(file);
    alert(html);

}

});

IS MULTIPART is showing true but how to get the file name and how to store it. I have tried an example without ajax and it works fine using datatype CommonsMultipartFile.
Also I have used ajaxupload in PHP and I get the filename as $_FILES[‘image’][‘name’] but no idea in java as I am new to java.
I have followed my similar question on this site but no success.

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-20T21:12:18+00:00Added an answer on May 20, 2026 at 9:12 pm

    You can make this shorter. You need a multipart-resolver:

    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    
        <!-- one of the properties available; the maximum file size in bytes -->
        <property name="maxUploadSize" value="100000"/>
    </bean>
    

    And then:

    @Controller
    public class FileUpoadController {
    
        @RequestMapping(value = "/form", method = RequestMethod.POST)
        public String handleFormUpload(@RequestParam("file") MultipartFile file) {
    
            if (!file.isEmpty()) {
                byte[] bytes = file.getBytes();
                // store the bytes somewhere
               return "redirect:uploadSuccess";
           } else {
               return "redirect:uploadFailure";
           }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple form like this: <form name=serachForm method=post action=/home/search> <input type=text name=searchText
I have simple form. <form target=_blank action=somescript.php method=Post id=simpleForm> <input type=hidden name=url value=http://...> <input
I have a simple form with some plain html input like bellow using ASP.NET
I have a simple html form: <form action="/api/userattributes" method=get> <select name=action> <option>read_by_user</option> <option>set</option> <option>delete</option>
I have a simple form like this: <form id='myForm'> <input type='text' name='Textbox'> <select name='SelectBox'>
I have simple form like this which accepts only two values string action and
Have a simple form (only extract fields here) but for some reason the JQserilization
I have have a simple HTML form with say four input widgets (see below)...two
I have a simple form for shipping options and I am using javascript to
I have a simple form that enables selecting an option (radio button). Upon selection

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.