grails - Grails文件上传未使用正确的内容类型

标签 grails groovy spring-security gsp

我在Grails中创建了文件上传,但是找不到找到使用Content-Type:multipart/form-data的请求的方法。请求与Content-Type:application/x-www-form-urlencoded

这是我的表格

        <g:uploadForm controller='asset' action='upload'>
            <label>Select file(s) to upload</label>
            <input type='file' id='fileUpload' name='filesToUpload' multiple />
            <g:submitButton name="upload" value="Upload"/>
        </g:uploadForm>

在Config.groovy中,grails.mime.types包含multipartForm: 'multipart/form-data'grails.web.disable.multipart=false。我正在使用Spring Security,AssetsController@Secured

如何获得要使用Content-Type:multipart/form-data发送的请求?

最佳答案

如果<g:uploadForm > -Tag不是手册中描述的内容:

http://grails.github.io/grails-doc/2.5.x/ref/Tags/uploadForm.html

Identical to the standard form tag except that it sets the enctype attribute to "multipart/form-data" automatically.



那么您可以尝试使用普通的<g:form > -Tag并添加enctype属性,甚至根本不使用标签。一个简单的HTML-Upload也可以工作:
<form action="${g:createLink controller:'', action:''}" method="post" enctype="multipart/form-data">
    <input type="file" name="fileupload">
    <input type="submit" name="upload">
</form>

关于grails - Grails文件上传未使用正确的内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29150015/

相关文章:

hibernate - 如何显示Grails( hibernate )中特定行的真实SQL?

grails - Grails GORM findAll返回null集合

grails - 在Grails自定义标签库中查找父标签

java - 我应该如何在 Spring MVC 中创建 Groovy Controller

groovy - 如何在groovy脚本中将数组排序为3个元素的组

grails - Grails 中没有双向关系的级联删除

grails - Grails 中的 Sprintf

java - 为什么我的所有 Spring boot 执行器端点都是公开可用的?

java - Spring 安全检查的 header 存在一些固定值

java - 缺少 Spring Security 类