for (FormField field : formData.getFields()) if (field.getIsFile())
// 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); }
/** * 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; }
/** * Constructs a FieldData object from a WebScript FormField object * * @param field The WebScript FormData object to create the field from */ public FieldData(FormField field) { this.name = field.getName(); this.value = field.getValue(); this.isFile = field.getIsFile(); if (isFile) { is = field.getInputStream(); } }
/** * Constructs a FieldData object from a WebScript FormField object * * @param field The WebScript FormData object to create the field from */ public FieldData(FormField field) { this.name = field.getName(); this.value = field.getValue(); this.isFile = field.getIsFile(); if (isFile) { is = field.getInputStream(); } }
/** * Cleanup any temporary resources associated with this form field * * NOTE: This should only be invoked after processing (e.g. retrieval of content) of the form field is done */ public void cleanup() { if (getIsFile()) { file.delete(); } } }
/** * Cleanup any temporary resources associated with this form field * * NOTE: This should only be invoked after processing (e.g. retrieval of content) of the form field is done */ public void cleanup() { if (getIsFile()) { file.delete(); } } }
/** * Cleanup any temporary resources associated with this form field * * NOTE: This should only be invoked after processing (e.g. retrieval of content) of the form field is done */ public void cleanup() { if (getIsFile()) { file.delete(); } } }