Carlos Gavidia Carlos Gavidia - 7 months ago 43
Java Question

Sent request parameters to UploadAction in gwt-upload

I get gwt-upload working in a GAE application. As suggested, I implemented a Custom UploadAction to handle the storage of the file in the DataStore. The code goes like this:

public String executeAction(HttpServletRequest request,
List<FileItem> sessionFiles) throws UploadActionException {"Starting: DatastoreUploadAction.executeAction");
String executeAction = super.executeAction(request, sessionFiles);

for (FileItem uploadedFile : sessionFiles) {
Long entityId = new Long(2001); // This is where i wanna use a request parameter
InputStream imgStream;
try {
imgStream = uploadedFile.getInputStream();
Blob attachment = new Blob(IOUtils.toByteArray(imgStream));
String contentType = uploadedFile.getContentType();
appointmentDao.setAppointmentAttachment(entityId, attachment,
} catch (IOException e) {
logger.error("Unable to store file", e);
throw new UploadActionException(e);


return executeAction;

As you see, the DAO class requires the "EntityID" to store the uploaded file in the DataStore. Now i'm working with a hard-coded value and it goes fine, but i'd like to have the entityID sent by the client as a request parameter. The widget that does the upload is a MultiUploader:

private MultiUploader defaultUploader;

Is it posible to the MultiUploader -or any other Widget- to set a request parameter so i can use it in my UploadAction?


Yes, you can set it on your client-side code.
There is method: MultiUploader #setServletPath(java.lang.String), for example:

  final MultiUploader u = new MultiUploader();
  u.setServletPath(u.getServletPath() + "?entityId="+myObject.getEntityId());

on server side:

  String entityId= request.getParameter("entityId"); 

Read this for more information: Sending additional parameters to the servlet