mysql - grails - Downloading PDF getting empty file -
i'm storing files within mysql database. corresponding domain class looks follows:
import org.springframework.web.multipart.commons.commonsmultipartfile import grails.persistence.entity @entity class document extends baseclass { string documentreference commonsmultipartfile cmffile static constraints = { documentreference nullable: true, maxsize: 500 } static mapping = { cmffile sqltype: "mediumblob" } }
i managed store different files within table in database. want enable user download of these files using following action:
def download(document documentinstance) { if (documentinstance == null) { notfound() return } response.setcontenttype(documentinstance?.cmffile?.contenttype) response.setheader("content-disposition", "attachment;filename=${documentinstance?.cmffile?.originalfilename}") response.outputstream << documentinstance?.cmffile?.getbytes() response.outputstream.flush() return true }
my problem downloading works fine .docx, textfiles or images. however, when i'm trying download e.g. .pdf or .zip files empty. don't know difference i'm passing on content type.
i greatful help! thank you!
i use grails (2.3.11) , store files in mysql , works charm.
the differences can see are:
domain
i use blob
type instead of commonsmultipartfile
, type: 'blob'
instead of sqltype: 'mediumblob'
. set value such field can use new javax.sql.rowset.serial.serialblob(byte[])
.
controller
i use (adjusted naming):
response.setcontenttype(servletcontext.getmimetype(documentinstance?.cmffile?.originalfilename)) response.setheader("content-disposition", "inline;filename=${documentinstance?.cmffile?.originalfilename}") response.outputstream << documentinstance?.cmffile?.getbytes()
no flush()
, no return true
.
notes
i noticed use quite small maxsize
constraint. 500 b not much. sure it's enough pdfs or zips?
besides, sure documentinstance?.cmffile
not null?
Comments
Post a Comment