Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store a file in the database with Grails

I need to store a file in the database using Grails. So, do you know how I can do that? Which data type should I use in the domain class (byte[] might be a solution)?

like image 576
rtacconi Avatar asked Apr 06 '09 13:04

rtacconi


2 Answers

See Chapter on Uploading Files in the Grails User Guide. It is also possible to use a java.sql.Blob as type for the binary content (which would be preferable when dealing with huge files).

like image 111
Siegfried Puchbauer Avatar answered Nov 15 '22 12:11

Siegfried Puchbauer


alternatively, store the file on disk, and store the path to it in the database. it is generally faster to access that file on disk than in a db. but of course, that really just depends on your needs in the app. But be aware of this alternative.

like image 32
Chii Avatar answered Nov 15 '22 10:11

Chii