简体   繁体   English

使用Grails 2.3.7上传时获取错误为invalidFormatException

[英]Getting the error as invalidFormatException while upload using grails 2.3.7

DocumentController.groovy DocumentController.groovy

def upload() {
              def file =request.getFile('file')
              def excelImportService
              XSSFWorkbook book = new XSSFWorkbook(file.getInputStream());
              Map CONFIG_BOOK_COLUMN_MAP = [
             sheet:'Sheet1',
             startRow: 1,
             columnMap:  [
              //Col, Map-Key
              'A':'Question',
              'B':'SecType',
              'C':'Option1',
              'D':'Option2',
              'E':'Option3',
              'F':'Option4',
              'G':'CorrectAnswer',
              'H':'QuestionOrder'
             ]
            ]
         //Iterate through bookList and create/persists your domain instances
          def bookList = excelImportService.columns(book, CONFIG_BOOK_COLUMN_MAP)

While uploading the excel file with the same format getting the Error: 在上传具有相同格式的excel文件时出现错误:

2014-04-30 15:49:31,024 [http-bio-8080-exec-9] ERROR errors.GrailsExceptionResolver  - InvalidFormatException occurred when processing request: [POST] /Application/document/upload - parameters:**
    upload: Upload                    
    Package should contain a content type part [M1.13]. Stacktrace follows:
    Message: Package should contain a content type part [M1.13]
        Line | Method

Instead of: 代替:

XSSFWorkbook book = new XSSFWorkbook(file.getInputStream());

You should use: 您应该使用:

Workbook book = WorkbookFactory.create(file.inputStream);

And

def excelImportService

Should be removed from the upload() method, and instead put as a property of the DocumentController class 应该从upload()方法中删除,而应作为DocumentController类的属性放置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM