Michael
Michael

Reputation: 33307

How to get the Mime Type of a request in Grails?

How to get the Mime Type of a request in Grails?

I used:

def f = request.getFile('image')
def mimeType = f.getContentType()

but this does not always returns the correct mime file type. How can I get File of file user selected for update?

Upvotes: 0

Views: 1187

Answers (2)

Pablo Pazos
Pablo Pazos

Reputation: 3216

You can get something like "text/xml; charset=UTF-8", so you might need to split by the ";" to get the correct value. Then you need to check if the value is valid, like checking the format, or checking against a list of valid codes, etc. If the value is not valid, you can return a 400 error to the user.

Upvotes: 0

Ian Roberts
Ian Roberts

Reputation: 122394

That will return whatever content type the browser sent for that particular part of the posted multipart/form-data. Whether or not this is the "correct" type is a different question...

Upvotes: 1

Related Questions