@@ -28,53 +28,24 @@ public void doTag() throws JspException, IOException {
2828 if (cloudinary == null ) {
2929 throw new JspException ("Cloudinary config could not be located" );
3030 }
31+ Uploader uploader = cloudinary .uploader ();
3132
32- StringBuilder renderedHtml = new StringBuilder ();
33-
34- renderedHtml .append ("<input " );
35-
36- Map <String , String > attributes = new HashMap <String , String >();
37- attributes .put ("type" , "file" );
38- attributes .put ("name" , name );
33+ Map <String , Object > htmlOptions = new HashMap <String , Object >();
34+ htmlOptions .put ("type" , "file" );
35+ htmlOptions .put ("name" , name );
3936 if (id != null ) {
40- attributes .put ("id" , id );
37+ htmlOptions .put ("id" , id );
4138 }
4239
4340 Map <String , String > options = new HashMap <String , String >();
4441 options .put ("resource_type" , resourceType );
4542 if (tags != null ) {
4643 options .put ("tags" , tags );
4744 }
48-
49- String cloudinaryUrl = cloudinary .cloudinaryApiUrl ("upload" , options );
50-
51- Uploader uploader = new Uploader (cloudinary );
52- Map <String , Object > params = uploader .buildUploadParams (options );
53- uploader .signRequestParams (params , options );
54-
55- attributes .put ("data-url" , cloudinaryUrl );
56-
57- StringBuilder jsonParams = new StringBuilder ();
58- jsonParams .append ("{" );
59- for (Map .Entry <String , Object > entry : params .entrySet ()) {
60- if (entry .getValue () != null ) {
61- jsonParams .append ("'" + entry .getKey () + "':'" + entry .getValue () + "'," );
62- }
63- }
64- jsonParams .append ("}" );
65- String escapedJsonParams = StringEscapeUtils .escapeHtml4 (jsonParams .toString ());
66-
67- attributes .put ("data-form-data" , escapedJsonParams );
68- attributes .put ("data-cloudinary-field" , fieldName );
69- attributes .put ("class" , "cloudinary-fileupload" + ((extraClasses != null ) ? " " + extraClasses : "" ));
70-
71- for (Map .Entry <String , String > entry : attributes .entrySet ()) {
72- renderedHtml .append (" " + entry .getKey () + "=\" " + entry .getValue () + "\" " );
73- }
7445
75- renderedHtml . append ( "/>" );
46+ String renderedHtml = uploader . imageUploadTag ( fieldName , options , htmlOptions );
7647
77- getJspContext ().getOut ().println (renderedHtml . toString () );
48+ getJspContext ().getOut ().println (renderedHtml );
7849 }
7950
8051 public void setId (String id ) {
0 commit comments