<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <!-- property name="maxUploadSize" value="100000" / --> </bean>
<form:form modelAttribute="cmd" method="post" enctype="multipart/form-data"> <input type="file" name="file"/> </form:form>
public String sync(@RequestParam(value = "file", required = false) MultipartFile uploadFile) throws IOException { // ... }
會得到這樣的錯誤訊息:
Uncaught exception from servlet java.lang.NoClassDefFoundError: java.rmi.server.UID is a restricted class. Please see the Google App Engine developer's guide for more details. at com.google.apphosting.runtime.security.shared.stub.java.rmi.server.UID.(UID.java) at org.apache.commons.fileupload.disk.DiskFileItem. (DiskFileItem.java:109) at org.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:199) at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:361) at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
Google 了一下,Google 已經針對這狀況提出解決方法了。
就是將 Spring MVC 的 MultipartFile 與 MultipartResolver 換成 Google 提供的對應 class 就可以了。
先去下載 gmultipart,有提供 Maven 的 dependency。
再改用 GmultipartResolver 與 GmultipartFile 就搞定了。
<bean id="multipartResolver" class="org.gmr.web.multipart.GMultipartResolver"> <!-- property name="maxUploadSize" value="100000" / --> </bean>
public String sync(@RequestParam(value = "file", required = false) GMultipartFile uploadFile) throws IOException { // ... }---
沒有留言:
張貼留言