Add FileUtil#getContentType().

This commit is contained in:
takezoe
2013-10-04 04:17:30 +09:00
parent f4f2bf34fc
commit 380cdbcf75
3 changed files with 14 additions and 16 deletions

View File

@@ -16,6 +16,16 @@ object FileUtil {
}
}
def getContentType(name: String, bytes: Array[Byte]): String = {
defining(getMimeType(name)){ mimeType =>
if(mimeType == "application/octet-stream" && isText(bytes)){
"text/plain"
} else {
mimeType
}
}
}
def isImage(name: String): Boolean = getMimeType(name).startsWith("image/")
def isLarge(size: Long): Boolean = (size > 1024 * 1000)