简体   繁体   English

ArrayIndexOutOfBoundsException失败

[英]ArrayIndexOutOfBoundsException grails

I have this simple controller which uploads a file into the database. 我有这个简单的控制器,可以将文件上传到数据库中。 I have a working view which displays the form for uploading, but when I click on the upload button, I run into this error at the documentInstance.save() line: ArrayIndexOutOfBoundsException occurred when processing request:[POST]/myApp/documentFile/upload 我有一个工作视图,其中显示要上载的表单,但是当我单击上载按钮时,我在documentInstance.save()行遇到此错误: 处理请求:[POST] / myApp / documentFile / upload时发生了ArrayIndexOutOfBoundsException

class DocumentController {
    def upload() {
        def file = request.getFile('file')
        if(file.empty) {
            flash.message = "File cannot be empty"
        } else {
            def documentInstance = new Document()
            documentInstance.filename = file.originalFilename
            documentInstance.filedata = file.getBytes()
            documentInstance.save()
        }
        redirect (action:'list')
    }
}

Can anyone help me understand where the problem lies? 谁能帮助我了解问题出在哪里? Is the information I have given sufficient for answering this? 我提供的信息足以回答这个问题吗? If not please let me know. 如果没有,请告诉我。

UPDATE: 更新:

form element part of the gsp is as below. gsp的form元素部分如下。

           <g:uploadForm action="upload">
                <fieldset class="form">
                    <input type="file" name="file" />
                </fieldset>
                <fieldset class="buttons">
                    <g:submitButton name="upload" class="save" value="Upload" />
                </fieldset>
            </g:uploadForm>

Here is the Document domain class 这是Document域类

class Document{

    String filename
    byte[] fileData

    static constraints = {
        filename(blank:false,nullable:false)
        filedata(blank: true, nullable:true, maxSize:1073741824)
    }
}

Try setting 'size' or 'maxSize' constraints on your domain objects 'filedata' field according to the size of the files you are uploading. 尝试根据要上传的文件的大小在域对象“文件数据”字段上设置“大小”或“最大大小”约束。 Your database might be creating small columns that cannot hold the file size you are uploading. 您的数据库可能正在创建小的列,无法容纳您要上传的文件大小。 According to http://grails.org/doc/latest/guide/theWebLayer.html#uploadingFiles 根据http://grails.org/doc/latest/guide/theWebLayer.html#uploadingFiles

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

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