question: public static Map < String , Object > uploadImageAndParameters ( HttpServletRequest request , String uploadField ) { Locale locale = UtilHttp . getLocale ( request ) ; Map < String , Object > results = FastMap . newInstance ( ) ; Map < String , String > formInput = FastMap . newInstance ( ) ; results . put ( "formInput" , formInput ) ; ServletFileUpload fu = new ServletFileUpload ( new DiskFileItemFactory ( 10240 , new File ( new File ( "runtime" ) , "tmp" ) ) ) ; List < FileItem > lst = null ; try { lst = UtilGenerics . checkList ( fu . parseRequest ( request ) ) ; } catch ( FileUploadException e4 ) { return ServiceUtil . returnError ( e4 . getMessage ( ) ) ; } if ( lst . size ( ) == 0 ) { String errMsg = UtilProperties . getMessage ( err_resource , "layoutEvents.no_files_uploaded" , locale ) ; request . setAttribute ( "_ERROR_MESSAGE_" , errMsg ) ; return ServiceUtil . returnError ( UtilProperties . getMessage ( err_resource , "layoutEvents.no_files_uploaded" , locale ) ) ; } FileItem fi = null ; FileItem imageFi = null ; for ( int i = 0 ; i < lst . size ( ) ; i ++ ) { fi = lst . get ( i ) ; String fieldName = fi . getFieldName ( ) ; String fieldStr = fi . getString ( ) ; if ( fi . isFormField ( ) ) { formInput . put ( fieldName , fieldStr ) ; request . setAttribute ( fieldName , fieldStr ) ; } if ( fieldName . equals ( uploadField ) ) { imageFi = fi ; results . put ( "uploadMimeType" , fi . getContentType ( ) ) ; } } if ( imageFi == null ) { String errMsg = UtilProperties . getMessage ( err_resource , "layoutEvents.image_null" , UtilMisc . toMap ( "imageFi" , imageFi ) , locale ) ; request . setAttribute ( "_ERROR_MESSAGE_" , errMsg ) ; return null ; } byte [ ] imageBytes = imageFi . get ( ) ; ByteBuffer byteWrap = ByteBuffer . wrap ( imageBytes ) ; results . put ( "imageData" , byteWrap ) ; results . put ( "imageFileName" , imageFi . getName ( ) ) ; return results ; }
target:  Uploads image data from a form and stores it in ImageDataResource. Expects key data in a field identitified by the "idField" value and the binary data to be in a field id'd by uploadField.