我在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/