FormPanel does not upload file in Firefox
Having a peculiar problem.
I'm using a FormPanel to send data to a database and uploading a file.
In Chrome this works fine, but in Firefox it sends the data to the database but does not upload the file. Firebug returns the following error:
Form contains a file input, but is missing method=POST and enctype=multipart/form-data on the form. The file will not be sent.
I found this weird. Checked the page source code and everything seems fine:
<form target="FormPanel_revanweb_1" action="phpFiles/newBookmark.php" enctype="ENCODING_MULTIPART" method="POST" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;" class="gwt-TabLayoutPanelContent">
This is how I built the form panel using UiBinder:
<g:FormPanel ui:field="formPanel" action="phpFiles/newBookmark.php" method="POST" encoding="ENCODING_MULTIPART">
<g:VerticalPanel ui:field="tabNewWrapper" stylePrimaryName="tabNew-wrapper">
<g:HTMLPanel ui:field="bookmarkNamePanel" styleName="container">
<g:Label text="Bookmark Name:" />
<g:TextBox name="txtBookmarkName" ui:field="txtBookmarkName" width="100%" />
</g:HTMLPanel>
<g:HTMLPanel ui:field="bookmarkURLPanel" styleName="container">
<g:Label text="Bookmark URL:" styleName="label" />
<g:TextBox name="txtBookmarkURL" ui:field="txtBookmarkURL" width="100%" />
</g:HTMLPanel>
<g:HTMLPanel ui:field="bookmarkDescriptionPanel" styleName="container">
<g:Label text="Bookmark Description" styleName="label" />
<g:TextArea name="txtBookmarkDescription" ui:field="txtBookmarkDescription" width="100%" height="60px" />
</g:HTMLPanel>
<g:HTMLPanel ui:field="bookmarkImgUploadPanel" styleName="container">
<g:Label text="Image:" styleName="label" />
<g:VerticalPanel ui:field="vpForm">
<g:FileUpload name="logo" ui:field="u开发者_StackOverflowploadFile" />
</g:VerticalPanel>
</g:HTMLPanel>
<g:HTMLPanel ui:field="bookmarkcbActivePanel" styleName="container">
<g:CheckBox name="cbActive" ui:field="cbActive" text="Active?" styleName="label" />
</g:HTMLPanel>
<g:HTMLPanel ui:field="bookmarkTagsPanel" styleName="container">
<g:Label text="Tags:" styleName="label" />
<g:SuggestBox ui:field="sbBookmarkTags" animationEnabled="true" width="100%" />
</g:HTMLPanel>
<g:HTMLPanel ui:field="btnOKPanel" styleName="container">
<g:SubmitButton ui:field="btnSubmit" text="OK" styleName="buttonOK" />
<g:Label ui:field="lblWarning" visible="false" styleName="warning" />
<g:Hidden ui:field="sessionID" name="sessionid" visible="false" />
</g:HTMLPanel>
</g:VerticalPanel>
</g:FormPanel>
You're setting the encoding to ENCODING_MULTIPART
, not multipart/form-data
.
NB: ENCODING_MULTIPART
is a constant of type String
, its not an enum; setEncoding
on FormPanel
takes a String
as argument; so if you write ENCODING_MULTIPART in your ui.xml, you'll set the string to "ENCODING_MULTIPART"
, not the value of the FormPanel.ENCODING_MULTIPART
constant (which, btw, can only be referenced in a ui.xml using a <ui:import field="com.google.gwt.user.client.ui.FormPanel.ENCODING_MULTIPART" />
, and then used as {ENCODING_MULTIPART}
)
精彩评论