Monday, March 29, 2010

Checking for mimetype during a file upload

The code below will only accept files of type .pdf

file = request.getFile('fileAttachment')
FileNameMap fileNameMap = URLConnection.getFileNameMap();
def contentType = fileNameMap.getContentTypeFor(file.originalFilename)
if (contentType != 'application/pdf') {
return error
}

No comments: