0

my jps file

<form id="createGroupForm"  method="POST" enctype="multipart/form-data">
        <div class="row upload-create-ag-data">
            <p class="ibmbr-title"><fmt:message  bundle="${msg}" key="ibmDisc.title"/></p>
            <div class="col-sm-6">
                <input class="form-control" type="file" name="uploadFile" id="uploadFile" accept="*.xls">
            </div>
            <div class="col-sm-6">
                <input class="btn btn-primary" type="button" style="height: 34px; margin-bottom: 5px; line-height: 0;" id="uploadGroupDetails" name="uploadGroupDetails" value='<fmt:message bundle="${pages}" key="CreateGroupFileUpload.upload"/>'/>
            </div>
        </div>
        </form>

My Controller

    @RequestMapping(value = "/CreateGroup", method = RequestMethod.POST, consumes = "multipart/form-data")
public @ResponseBody HttpServletResponse createGroup(@RequestParam(value = "uploadFile", required = true) MultipartFile uploadFile, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

when I submit the above form by uploading a xls file say group.xls it has been saved as XXXXXXXXX.tmp file in tomcat folder. Am trying to create a workbook using the received MultipartFile in the controller.

Workbook excelWorkBook = new HSSFWorkbook(uploadFile.getInputStream());

The above line is throwing some unknow exception. Tried multiple solution few from web and few from stackoverflow nothing worked. For example the below sol(SolFromStackoverflow) creating a file with .xls using recieved multipart file but am not able to open that .xls file, its corrupted.

String destFilePath = "/root/git/" + orgName;
        File dest = new File(destFilePath);
        try {
            uploadFile.transferTo(dest);
            boolean canRead = dest.canRead();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

First of all why spring is saving the uploaded file(group.xls) in the form of .tmp? Does mean that the file is corrupted? Please suggest if am missing anyting.

your time will be appreciated.

3
  • 1
    Spring isn't saving anything, that is how tomcat temporarily stores the file content. Opening that with an inputstream shouldn't be any problem. Instead of hunting a problem that isn't one, fix the exception you get while reading from the input stream. Commented Jan 26, 2021 at 11:00
  • hi @M.Deinum, Thanks for your time. Am getting this exception message - Invalid header signature; read 0xE011BDBFEFBDBFEF, expected 0xE11AB1A1E011CFD0. How I can back trace if its security issue? Please help Commented Jan 27, 2021 at 4:40
  • Are you uploading an XLS or an XLSX file? They are quite different in structure. Instead of new HSSFWorkbook(uploadFile.getInputStream()); use WorkbookFactory.create(uploadFile.getInputStream()); and it will automatically detect the proper format. Looks like you are trying to use the wrong workbook format to load your file. Commented Jan 27, 2021 at 7:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.