Expand my Community achievements bar.

SOLVED

Multipart form and servlet in CQ

Avatar

Level 4

Hi,

We are trying to automate the uploading of files to DAM.  Our webpage contains the following input(s)

<input type="hidden" id="dam-root" name="dam-root" value="/content/dam/travel/"/> <input id="file-id" type="file" name="our-file" />

We referenced the article http://labs.sixdimensions.com/blog/2013-01-02/handling-file-upload-adobe-cq/ to implement our servlet.  Specifically, to get the values from the form, we are using

// process file String fileName = ""; InputStream fstream = null; final boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart) { final Map<String, RequestParameter[]> params = request.getRequestParameterMap(); for (final Map.Entry<String, RequestParameter[]> pairs : params.entrySet()) { final String k = pairs.getKey(); final RequestParameter[] pArr = pairs.getValue(); final RequestParameter param = pArr[0]; final InputStream stream = param.getInputStream(); if (param.isFormField()) { log.info("Form field " + k + " with value " + Streams.asString(stream) + " detected."); } else { fstream = stream; fileName = param.getFileName(); } } }

However, when we run the code, we expect the log file to record "Form field dam-root with value /content/dam/travel/ detected".  However, non-file form fields are never detected.  It detects the file input request parameter aka "our-file" and process the related stream.  Any pointers?

Thank You.

1 Accepted Solution

Avatar

Correct answer by
Level 4

Silly me, I found my mistake.  The servlet is not detecting form fields because the JSP page has a client script that filters out all form fields and sending only file input.  

View solution in original post

1 Reply

Avatar

Correct answer by
Level 4

Silly me, I found my mistake.  The servlet is not detecting form fields because the JSP page has a client script that filters out all form fields and sending only file input.