-
Oct 6th, 2006, 12:03 PM
#1
Error using fileupload sample
Hi all,
I tried to modify my code to use the example of file upload provided by spring-webflow-1.0-rc3. I am now experiencing this error and not quite sure how to fix this (see stack trace below). The error msg seems to imply that when FileUploadAction.java (see below) gets "csv_file" attribute sent by request, the attribute is a string type which is confusing to me. As you can see from view.jsp (see below), I did declare "csv_file" is typed "file". Do you know what I am doing wrong here?
Thanks so much for your help,
Thong Bui
==========================
1) Stack trace:
java.lang.IllegalArgumentException: Map key 'csv_file' has value [427.csv] that is not of expected type [interface org.springframework.web.multipart.MultipartFile], instead it is of type [java.lang.String]
org.springframework.binding.util.MapAccessor.asser tKeyValueInstanceOf(MapAccessor.java:455)
org.springframework.binding.util.MapAccessor.asser tKeyValueOfType(MapAccessor.java:442)
org.springframework.binding.util.MapAccessor.get(M apAccessor.java:95)
org.springframework.binding.util.MapAccessor.get(M apAccessor.java:78)
org.springframework.webflow.ParameterMap.getMultip artFile(ParameterMap.java:244)
com.real.rhapsody.webflow.fileupload.FileUploadAct ion.doExecute(FileUploadAction.java:14)
org.springframework.webflow.action.AbstractAction. execute(AbstractAction.java:204)
org.springframework.webflow.AnnotatedAction.execut e(AnnotatedAction.java:139)
org.springframework.webflow.ActionExecutor.execute (ActionExecutor.java:58)
org.springframework.webflow.ActionState.doEnter(Ac tionState.java:176)
org.springframework.webflow.State.enter(State.java :194)
org.springframework.webflow.Transition.execute(Tra nsition.java:220)
org.springframework.webflow.TransitionableState.on Event(TransitionableState.java:102)
org.springframework.webflow.Flow.onEvent(Flow.java :603)
org.springframework.webflow.execution.impl.Request ControlContextImpl.signalEvent(RequestControlConte xtImpl.java:199)
org.springframework.webflow.execution.impl.FlowExe cutionImpl.signalEvent(FlowExecutionImpl.java:193)
org.springframework.webflow.executor.FlowExecutorI mpl.signalEvent(FlowExecutorImpl.java:228)
org.springframework.webflow.executor.support.FlowR equestHandler.handleFlowRequest(FlowRequestHandler .java:113)
org.springframework.webflow.executor.mvc.FlowContr oller.handleRequestInternal(FlowController.java:19 9)
org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(AbstractController.java:153)
org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(SimpleControllerHandlerAda pter.java:45)
org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:798)
org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:728)
org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:396)
org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:350)
javax.servlet.http.HttpServlet.service(HttpServlet .java:689)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
com.opensymphony.module.sitemesh.filter.PageFilter .parsePage(PageFilter.java:118)
com.opensymphony.module.sitemesh.filter.PageFilter .doFilter(PageFilter.java:52)
==================================================
2) FileUploadAction.java:
1 package com.real.rhapsody.webflow.fileupload;
2
3 import org.springframework.web.multipart.MultipartFile;
4 import org.springframework.webflow.Event;
5 import org.springframework.webflow.RequestContext;
6 import org.springframework.webflow.action.AbstractAction;
7
8 import java.io.File;
9 import java.util.Date;
10 import java.text.SimpleDateFormat;
11
12 public class FileUploadAction extends AbstractAction {
13 protected Event doExecute(RequestContext context) throws Exception {
14 MultipartFile file = context.getRequestParameters().getMultipartFile("c sv_file");
15 if (!file.isEmpty()) {
16 SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");
17 // TODO: we need to set up a directory to upload file and use it here
18 File tempFile = new File(file.getName() + "_" + formatter.format(new Date()));
19 file.transferTo(tempFile);
20
21 context.getRequestScope().put("file", tempFile);
22 // TODO: we now need to call publishingFileloaderService.
23 }
24 else {
25 context.getRequestScope().put("file", null);
26 }
27 return success();
28 }
29 }
===============================================
3) view.jsp:
<%@ include file="includeTop.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form name="uploadSubmit" action="load" enctype="multipart/form-data">
<fieldset>
<legend>file upload form</legend>
<ol>
<li>
<label for="load_notes">Load notes</label>
<input name="load_notes"/>
</li>
<li>
<label for="tracking_number">Tracking number</label>
<input name="tracking_number"/>
</li>
<li>
<label for="csv_file">CSV File</label>
<input type="file" name="csv_file"/>
</li>
<li>
<fieldset>
<label>
<input type="hidden" name="_flowExecutionKey" value="${flowExecutionKey}"/>
<input type="submit" class="button" name="_eventId_submit" value="Upload"/>
</label>
</fieldset>
</li>
</ol>
</fieldset>
</form>
</body
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules