Convert base64 string to image

In the server, do something like this: Suppose String data=”data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAADwCAYAAAA+VemSAAAgAEl…==” Then: String base64Image = data.split(“,”)[1]; byte[] imageBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(base64Image); Then you can do whatever you like with the bytes like: BufferedImage img = ImageIO.read(new ByteArrayInputStream(imageBytes));

Grails BuildConfig.groovy, difference between build, compile, and runtime?

build – dependency that is only needed by the build process runtime – dependency that is needed to run the application, but not compile it e.g. JDBC implementation for specific database vendor. This would not typically be needed at compile-time because code depends only the JDBC API, rather than a specific implementation thereof compile – … Read more

How to access Grails configuration in Grails 2.0?

If you need it in an artifact that supports dependency injection, simply inject grailsApplication class MyController { def grailsApplication def myAction = { def bar = grailsApplication.config.my.property } } If you need it in a bean in, say, src/groovy or src/java, wire it up using conf/spring/resources.groovy // src/groovy/com/example/MyBean.groovy class MyBean { def grailsApplication def foo() … Read more

How to calculate elapsed time from now with Joda-Time?

To calculate the elapsed time with JodaTime, use Period. To format the elapsed time in the desired human representation, use PeriodFormatter which you can build by PeriodFormatterBuilder. Here’s a kickoff example: DateTime myBirthDate = new DateTime(1978, 3, 26, 12, 35, 0, 0); DateTime now = new DateTime(); Period period = new Period(myBirthDate, now); PeriodFormatter formatter … Read more

Found shared references to a collection org.hibernate.HibernateException

Hibernate shows this error when you attempt to persist more than one entity instance sharing the same collection reference (i.e. the collection identity in contrast with collection equality). Note that it means the same collection, not collection element – in other words relatedPersons on both person and anotherPerson must be the same. Perhaps you’re resetting … Read more

Copy entire directory contents to another directory? [duplicate]

FileUtils.copyDirectory() Copies a whole directory to a new location preserving the file dates. This method copies the specified directory and all its child directories and files to the specified destination. The destination is the new location and name of the directory. The destination directory is created if it does not exist. If the destination directory … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)