/** * Returns the FormField bject representing a file uploaded via a multipart form. * * @param name The name of the field containing the content * @return FormField bject representing a file uploaded via a multipart form or null * if the field does not exist or is not a file field. */ public FormField getFileField(String name) { FormField field = null; // attempt to find the requested field FormField[] fields = this.formData.getFields(); for (FormField f : fields) { if (f.getName().equals(name)) { // check the field is a file field if (f.getIsFile()) { field = f; } break; } } return field; }
/** * Returns the FormField bject representing a file uploaded via a multipart form. * * @param name The name of the field containing the content * @return FormField bject representing a file uploaded via a multipart form or null * if the field does not exist or is not a file field. */ public FormField getFileField(String name) { FormField field = null; // attempt to find the requested field FormField[] fields = this.formData.getFields(); for (FormField f : fields) { if (f.getName().equals(name)) { // check the field is a file field if (f.getIsFile()) { field = f; } break; } } return field; }
/** * Returns the FormField bject representing a file uploaded via a multipart form. * * @param name The name of the field containing the content * @return FormField bject representing a file uploaded via a multipart form or null * if the field does not exist or is not a file field. */ public FormField getFileField(String name) { FormField field = null; // attempt to find the requested field FormField[] fields = this.formData.getFields(); for (FormField f : fields) { if (f.getName().equals(name)) { // check the field is a file field if (f.getIsFile()) { field = f; } break; } } return field; }
/** * Gets parameters encoded in the form data * * @return map (name, value) of parameters */ /*package*/ public Map<String, String[]> getParameters() { if (parameters == null) { FormField[] fields = getFields(); parameters = new HashMap<String, String[]>(fields.length); for (FormField field : fields) { String[] vals = parameters.get(field.getName()); if (vals == null) { parameters.put(field.getName(), new String[] {field.getValue()}); } else { String[] valsNew = new String[vals.length +1]; System.arraycopy(vals, 0, valsNew, 0, vals.length); valsNew[vals.length] = field.getValue(); parameters.put(field.getName(), valsNew); } } } return parameters; }
/** * Gets parameters encoded in the form data * * @return map (name, value) of parameters */ /*package*/ public Map<String, String[]> getParameters() { if (parameters == null) { FormField[] fields = getFields(); parameters = new HashMap<String, String[]>(fields.length); for (FormField field : fields) { String[] vals = parameters.get(field.getName()); if (vals == null) { parameters.put(field.getName(), new String[] {field.getValue()}); } else { String[] valsNew = new String[vals.length +1]; System.arraycopy(vals, 0, valsNew, 0, vals.length); valsNew[vals.length] = field.getValue(); parameters.put(field.getName(), valsNew); } } } return parameters; }
/** * Gets parameters encoded in the form data * * @return map (name, value) of parameters */ /*package*/ public Map<String, String[]> getParameters() { if (parameters == null) { FormField[] fields = getFields(); parameters = new HashMap<String, String[]>(fields.length); for (FormField field : fields) { String[] vals = parameters.get(field.getName()); if (vals == null) { parameters.put(field.getName(), new String[] {field.getValue()}); } else { String[] valsNew = new String[vals.length +1]; System.arraycopy(vals, 0, valsNew, 0, vals.length); valsNew[vals.length] = field.getValue(); parameters.put(field.getName(), valsNew); } } } return parameters; }
// Get our multipart form final ResourceBundle rb = getResources(); final FormData form = (FormData)req.parseContent(); if (form == null || !form.getIsMultiPart()) { throw new ResourceBundleWebScriptException(Status.STATUS_BAD_REQUEST, rb, ERROR_BAD_FORM); } // Find the File Upload file, and process the contents boolean processed = false; for (FormData.FormField field : form.getFields()) { if (field.getIsFile()) { // Logic to process/save the file data here processUpload( field.getInputStream(), field.getFilename()); processed = true; break; } } // Object if we didn't get a file if (!processed) { throw new ResourceBundleWebScriptException(Status.STATUS_BAD_REQUEST, rb, ERROR_NO_FILE); }
for (FormField field : formData.getFields())