spring mvc - Grails request.getFile always returning null -
i've been trying submit form contains multiple inputs (texts , 1 image) i'm unable retrieve image request (grails 3.0.4)
my create.gsp looks this:
<g:uploadform controller="advertisement" action="save"> <input name="name" type="text" id="advertisement_name" /> <input name="link" type="text" id="advertisement_url" /> <input id="add_banner_image" name="myimage" type="file" accept="image/png,image/jpeg" data-max-size="512000"/> <g:submitbutton name="save" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" value="salvar anĂșncio"> </g:submitbutton> </g:uploadform> my browser shows correct request payload:
------webkitformboundarysaaghui2q9vtfkky content-disposition: form-data; name="name" filipe ------webkitformboundarysaaghui2q9vtfkky content-disposition: form-data; name="link" https://www.filipescosta.com ------webkitformboundarysaaghui2q9vtfkky content-disposition: form-data; name="imagemlouca"; filename="exemplo.jpeg" content-type: image/jpeg ------webkitformboundarysaaghui2q9vtfkky content-disposition: form-data; name="save" salvar anĂșncio my resources.groovy looks this:
beans = { multipartresolver (org.springframework.web.multipart.commons.commonsmultipartresolver) { maxuploadsize=2500000 } } and application.yml looks this:
grails: mime: disable: accept: header: useragents: - gecko - webkit - presto - trident types: all: '*/*' atom: application/atom+xml css: text/css csv: text/csv form: application/x-www-form-urlencoded html: - text/html - application/xhtml+xml js: text/javascript json: - application/json - text/json multipartform: multipart/form-data pdf: application/pdf rss: application/rss+xml text: text/plain hal: - application/hal+json - application/hal+xml xml: - text/xml - application/xml urlmapping: cache: maxsize: 1000 controllers: defaultscope: singleton converters: encoding: utf-8 views: default: codec: html gsp: encoding: utf-8 htmlcodec: xml codecs: expression: html scriptlets: html taglib: none staticparts: none my controller looks this:
def save() { println request.getfile('myimage') println "request class: ${request.class}" [...] request.withformat { form multipartform { flash.message = message(code: 'default.created.message', args: [message(code: 'advertisement.label', default: 'advertisement'), advertisement.id]) redirect(uri:'/') } '*' { respond advertisement, [status: created, formats:['html']] } } } but in console, println message is:
null request class: class org.springframework.web.multipart.support.defaultmultiparthttpservletrequest can take , me trick? i've been searching examples , couldn't find helps.
you define: attribute name="myimage" , try uppercase name -> request.getfile('myimage')
Comments
Post a Comment